﻿using DX_Recognize.Common;
using DX_Recognize.Entitys;
using DX_Recognize.Utils;
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using ZwSoft.ZwCAD.DatabaseServices;
using DX_Recognize.AuxiliaryTool;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Collections;
using ZwSoft.ZwCAD.DatabaseServices.Filters;
using DX_Recognize.UI;
using System.Threading;
using System.Reflection;
using Newtonsoft.Json.Linq;
using System.IO;
using DX_Recognize.Disposition;
using static DX_Recognize.Utils.ConvertUtils;
using Newtonsoft.Json;
using System.Diagnostics;
using DX_Recognize.View;
using ZwSoft.ZwCAD.ApplicationServices;
using ZwSoft.ZwCAD.EditorInput;
using ZwSoft.ZwCAD.Geometry;
using System.Net;
using System.Windows;
using System.Text.RegularExpressions;
using System.Security.Policy;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using ZwSoft.ZwCAD.GraphicsInterface;
using System.Data.SqlClient;
using System.Diagnostics.Eventing.Reader;
using AcadApp = ZwSoft.ZwCAD.ApplicationServices.Application;
using System.Net.NetworkInformation;
using DX_Recognize.PageView;


namespace DX_Recognize
{
    //声明委托 渲染数据
    public delegate void RCBoardBeCall(RenderType RType);
    public delegate void RCItemBeCall();
    public delegate void RCSItemBeCall(List<LabourSingleItem> SurplusItemList);
    //声明委托 精框 提示
    public delegate void FrameCall();
    //菜单弹出 
    public delegate void ShowMenuCall();
    //设置抓取模号文本
    public delegate void SetModeNumCall(string Str);
    public partial class DataForm : Form
    {
        
        [DllImport("user32.dll")]
        public static extern int SetFocus(IntPtr hWnd);

        //是否初次读取配置文件的账号
        public Boolean firstReadF = true;
        public string OldFancySelectItem = "";
        public BoardSelectForm BSForm = new BoardSelectForm();
        public UserLoginForm ULForm = new UserLoginForm();
        public RecordForm RFForm = new RecordForm();
        public KOHoleWindow koHoleWindow = new KOHoleWindow();
        public SpringHoleWindow springHoleWindow = new SpringHoleWindow();
        public EGPWindow egpWindow = new EGPWindow();
        public FrameWindow frameWindow = new FrameWindow();
        public SteelWindow steelWindow = new SteelWindow();
        public PullingWindow pullingWindow = new PullingWindow();
        public HttpUtils httpUtils = new HttpUtils();
        //目前正被操作的板Code
        public string NowOperBoardUID = null;
        public ComputedUtils CU = new ComputedUtils();
        //手动模式 系统
        public string MSYS = null;
        public DataForm()
        {
            InitializeComponent();
            //AcadApp.ShowModalDialog(frameWindow);
            List<UIItem> ItemUIList = new List<UIItem>();
            ItemUIList.Add(new UIItem("ReturnPin", "回针"));
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
             this.R2DControl.SelectedIndex = 0;
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                this.R2DControl.SelectedIndex = 1;
            if (AssemblyShareData.operType == CustomOperPatternType.TEMP)
                this.R2DControl.SelectedIndex = 2;
            ToggleUIShow();
        }

        //加载时
        private void DataForm_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
            this.Text = "当前版本:" + DataForm.VersionNum;
            RenderCustomerData();
            springHoleWindow.SAssemFunc += SHoleAssemFunc;
            springHoleWindow.SProjectionFunc += SProjectionFunc;
            koHoleWindow.KOProjectionFunc += KOHoleProjectionFunc;
            frameWindow.FrameSideMeaAction += FramSideLabelEvent;
            frameWindow.MTypeRenderAboutFrameUIAction += MTypeRenderMBoardFrameUIEvent;
            frameWindow.MotifyToChangeMainWinHoleUIAction += RenderMainWinHoleUI;
            BSForm.PassBoardAction += AddBoardOperAction;
            RFForm.ATypeResetRecordOper += ATypeRecordAction;
            RFForm.MTypeResetRecordOper += MTypeRecordAction;
            RFForm.RenderUIByCondi += RenderUploadRecordUI;
            steelWindow.SteelAction += ChoiseSteelAction;
            pullingWindow.PullingAction += PullingActionEvent;
            httpUtils.ChangePageControlSelectIndexAction += SetControlTempSelectIndexAction;
        }

        //渲染客户查询条件显示数据
        public void RenderCustomerData()
        {
            if (RFForm.CustomerSelect.Items.Count > 0)
                RFForm.CustomerSelect.Items.Clear();
            RFForm.CustomerSelect.Items.AddRange(ParamsConfigData.CustomerList.ToArray());
            RFForm.CustomerSelect.DisplayMember = "showContent";
            RFForm.CustomerSelect.ValueMember = "customerNumber";
        }

        //显示菜单
        public  void MenuShow()
        {
            SetFocus(this.Handle);
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
            this.Show();
        }

        //设置模号文本
        public void SetModeNumberValue(string ModeNum)
        {
            this.ModeNumText.Texts = ModeNum;
            MenuShow();
        }

        //自动模式 接受委托的方法 识别过程中 渲染关于板的页面UI数据
        public void AutoPageRenderBoardUIData(RenderType RType)
        {
            List<BoardSectionItem> BList = AssemblyShareData.AUIBlueSectionList;
            AutoPageBoardDataDrivenRenderUI(BList);
            if (RType == RenderType.AfterRecoginzeFrame)
                MenuShow();
        }

        //配板数据驱动页面渲染
        public void AutoPageBoardDataDrivenRenderUI(List<BoardSectionItem> ShowBList, Boolean recordF = false)
        {
            if (ShowBList.Count > 0)
            {
                BoardDataGridView.Rows.Clear();
                for (int i = 0; i < ShowBList.Count; i++)
                {
                    DataGridView ItemData = new DataGridView();
                    int rowIndex = BoardDataGridView.Rows.Add(ItemData);
                    BoardDataGridView.Rows[rowIndex].Cells["AddOper"] = new DXButtonCell("+");
                    BoardDataGridView.Rows[rowIndex].Cells["OperSub"] = new DXButtonCell("-");
                    BoardDataGridView.Rows[rowIndex].Cells["BoardUID"].Value = ShowBList[i].BoardUID;
                    BoardDataGridView.Rows[rowIndex].Cells["BoardName"].Value = ShowBList[i].BoardName;
                    if (ShowBList[i].ManualOperFlag)
                        BoardDataGridView.Rows[rowIndex].Cells["BoardName"].Style.BackColor = Color.LightGray;
                    BoardDataGridView.Rows[rowIndex].Cells["BoardCode"].Value = ShowBList[i].BoardCode;
                    BoardDataGridView.Rows[rowIndex].Cells["PlateNum"].Value = ShowBList[i].Num;
                    BoardDataGridView.Rows[rowIndex].Cells["BluePrintHHFlag"].Value = ShowBList[i].Hanging.BluePrintHHFlag;

                    Boolean sfangtieF = ShowBList[i].BoardCode.Equals("sfangtie");
                    Boolean fangtieF = ShowBList[i].BoardCode.Equals("fangtie");
                    Boolean mpBoardF = ShowBList[i].BoardCode.Equals("mpBoard");
                    
                    if(sfangtieF || fangtieF || mpBoardF)
                        BoardDataGridView.Rows[rowIndex].Cells["PlateNum"].ReadOnly = false;
                    else
                        BoardDataGridView.Rows[rowIndex].Cells["PlateNum"].ReadOnly = true;

                    if (!ShowBList[i].ManualOperFlag)
                        BoardDataGridView.Rows[rowIndex].Cells["OperSub"].Dispose();
                    BoardDataGridView.Rows[rowIndex].Cells["PlateLength"].Value = ShowBList[i].PlateLength;
                    BoardDataGridView.Rows[rowIndex].Cells["Steel"].Value = ShowBList[i].Steel.SteelName;
                    BoardDataGridView.Rows[rowIndex].Cells["PlateWidth"].Value = ShowBList[i].PlateWidth;
                    BoardDataGridView.Rows[rowIndex].Cells["PlateThick"].Value = ShowBList[i].PlateThick;
                    string FType = ShowBList[i].frameItem.FrameType;
                    Boolean FTF1 = FType.Equals("J");
                    Boolean FTF2 = FType.Equals("C");
                    if (FTF1)
                        BoardDataGridView.Rows[rowIndex].Cells["FrameType"].Value = "精框";
                    if (FTF2)
                        BoardDataGridView.Rows[rowIndex].Cells["FrameType"].Value = "粗框";

                    if (ShowBList[i].DimensionPlateThick != 0 && ShowBList[i].DimensionPlateThick != ShowBList[i].PlateThick)
                    {
                        BoardDataGridView.Rows[rowIndex].Cells["DimensionPlateThick"].Value = ShowBList[i].DimensionPlateThick;
                        BoardDataGridView.Rows[rowIndex].Cells["DimensionPlateThick"].Style.BackColor = Color.LightGray;
                    }

                    if (ShowBList[i].Hanging.HangingParam.Dim != 0)
                        BoardDataGridView.Rows[rowIndex].Cells["HangingDim"].Value = ShowBList[i].Hanging.HangingParam.Dim;
                    if (ShowBList[i].Hanging.Num != 0)
                        BoardDataGridView.Rows[rowIndex].Cells["HangingNum"].Value = ShowBList[i].Hanging.Num;

                    //拉令 自动补充
                    if (ShowBList[i].Hanging.standardType == StandardType.Untried)
                        BoardDataGridView.Rows[rowIndex].Cells["HangingHole"].Value = "";
                    if (ShowBList[i].Hanging.standardType == StandardType.Standard)
                        BoardDataGridView.Rows[rowIndex].Cells["HangingHole"].Value = "标准";
                    if (ShowBList[i].Hanging.standardType == StandardType.NonStandard)
                    {
                        BoardDataGridView.Rows[rowIndex].Cells["HangingHole"].Style.BackColor = Color.LightGray;
                        BoardDataGridView.Rows[rowIndex].Cells["HangingHole"].Value = "非标";
                    }
                    //客图没画 帮补充
                    if (!ShowBList[i].Hanging.BluePrintHHFlag && ShowBList[i].Hanging.HangingParam.Dim != 0)
                        BoardDataGridView.Rows[rowIndex].Cells["HangingDim"].Style.BackColor = Color.LightGray;
                    //加工框 提示数据
                    BoardDataGridView.Rows[rowIndex].Cells["FrameTig"].Value = ShowBList[i].frameItem.Tig;
                    //标准孔距
                    if (ShowBList[i].PitchHoleStandard == StandardType.Untried)
                        BoardDataGridView.Rows[rowIndex].Cells["HolePitch"].Value = "";
                    if (ShowBList[i].PitchHoleStandard == StandardType.Standard)
                        BoardDataGridView.Rows[rowIndex].Cells["HolePitch"].Value = "标准";
                    if (ShowBList[i].PitchHoleStandard == StandardType.NonStandard)
                    {
                        BoardDataGridView.Rows[rowIndex].Cells["HolePitch"].Style.BackColor = Color.LightGray;
                        BoardDataGridView.Rows[rowIndex].Cells["HolePitch"].Value = "非标";
                    }
                    //中托边孔距
                    if (ShowBList[i].EGPPitchHoleStandard == StandardType.Standard)
                        BoardDataGridView.Rows[rowIndex].Cells["EGPHolePitch"].Value = "标准";
                    if (ShowBList[i].EGPPitchHoleStandard == StandardType.NonStandard)
                    {
                        BoardDataGridView.Rows[rowIndex].Cells["EGPHolePitch"].Style.BackColor = Color.LightGray;
                        BoardDataGridView.Rows[rowIndex].Cells["EGPHolePitch"].Value = "非标";
                    }
                    //精框提示
                    BoardDataGridView.Rows[rowIndex].Cells["FrameTig"].Value = ShowBList[i].frameItem.Tig;
                }
            }
        }

        //渲染关于识别出来的零件的页面数据
        public void RenderItemUIData()
        {
            List<SingleItem> ItemList = ShareItemData.UIItemList;
            if (ItemDataGridView.Rows.Count > 0)
                ItemDataGridView.Rows.Clear();
            if (ItemList.Count > 0)
            {
                for (int i = 0; i < ItemList.Count; i++)
                {
                    DataGridView ItemData = new DataGridView();
                    int rowIndex = ItemDataGridView.Rows.Add(ItemData);
                    ItemDataGridView.Rows[rowIndex].Cells["decRItem"] = new DXButtonCell("-");
                    ItemDataGridView.Rows[rowIndex].Cells["ItemUID"].Value = ItemList[i].ItemUID;
                    ItemDataGridView.Rows[rowIndex].Cells["ItemName"].Value = ItemList[i].ItemName;
                    //导套在显示的时候显示外径Dim 落数的时候传BushSize
                    ItemDataGridView.Rows[rowIndex].Cells["Dim"].Value = ItemList[i].Dim;
                    //螺丝只设置理论长度
                    if (ComputedUtils.JudgeItemIsScrew(ItemList[i].ItemNameType))
                        ItemDataGridView.Rows[rowIndex].Cells["TheoryL"].Value = ItemList[i].TheoryScrewH;
                    else
                    {
                        //实际长度
                        ItemDataGridView.Rows[rowIndex].Cells["ActL"].Value = ItemList[i].RealH;
                        ItemDataGridView.Rows[rowIndex].Cells["TheoryL"].Value = ItemList[i].TheoryH;
                    }
                    ItemDataGridView.Rows[rowIndex].Cells["Num"].Value = ItemList[i].ItemNum;

                    if (ItemList[i].Remark != null)
                        ItemDataGridView.Rows[rowIndex].Cells["Remark"].Value = ItemList[i].Remark;
                }
            }
        }
        
        //渲染手动补充出来的零件的页面数据
        public void SurplusItemDrivenRenderUI(List<LabourSingleItem> SurplusItemList)
        {
            if (SurplusItemDataGridView.Rows.Count > 0)
                SurplusItemDataGridView.Rows.Clear();
            if (SurplusItemList.Count > 0)
            {
                for (int i = 0; i < SurplusItemList.Count; i++)
                {
                    DataGridView ItemData = new DataGridView();
                    int rowIndex = SurplusItemDataGridView.Rows.Add(ItemData);
                    SurplusItemDataGridView.Rows[rowIndex].Cells["AddLabourItem"] = new DXButtonCell("+");
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SubLabourItem"] = new DXButtonCell("-"); ;
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SurplusItemUID"].Value = SurplusItemList[i].ItemUID;
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SurplusItemName"].Value = SurplusItemList[i].ItemName;
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SurplusItemDim"].Value = SurplusItemList[i].ItemDim;
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SurplusItemLength"].Value = SurplusItemList[i].ItemL;
                    SurplusItemDataGridView.Rows[rowIndex].Cells["SurplusItemNum"].Value = SurplusItemList[i].ItemNum;
                }
            }
        }

        //Record 自动模式 接收委托 渲染记录的数据到识别界面上
        public void ATypeRecordResetPriDataOper(AMTypeUPloadRecordInfo RInfo, Boolean recordF = false)
        {
            String quoInfoStr = RInfo.quoInfo;
            JObject quoInfoJSON = JObject.Parse(quoInfoStr);
            String BoardStr = quoInfoJSON["BoardList"].ToString();
            String ItemStr = quoInfoJSON["ItemList"].ToString();
            string LabourItemStr = quoInfoJSON["LabourItemList"].ToString();
            List<BoardSectionItem> boardList = JsonConvert.DeserializeObject<List<BoardSectionItem>>(BoardStr);
            List<LabourSingleItem> ItemList = JsonConvert.DeserializeObject<List<LabourSingleItem>>(ItemStr);
            List<LabourSingleItem> LabourItemList = JsonConvert.DeserializeObject<List<LabourSingleItem>>(LabourItemStr);
            AutoPageBoardDataDrivenRenderUI(boardList, recordF);
            RecordItemDataRenderUI(ItemList);
            SurplusItemDrivenRenderUI(LabourItemList);
        }

        //手动模式 渲染记录的数据到界面上
        public void MTypeRecordResetPriDataOper(AMTypeUPloadRecordInfo RInfo, Boolean recordF = false)
        {
            String quoInfoStr = RInfo.quoInfo;
            JObject quoInfoJSON = JObject.Parse(quoInfoStr);
            String BoardStr = quoInfoJSON["MBoardList"].ToString();
            String ItemStr = quoInfoJSON["MItemList"].ToString();
            String CBStr = quoInfoJSON["CBInfo"].ToString();
            AssemblyShareData.MSectionList = JsonConvert.DeserializeObject<List<ManualBoardItem>>(BoardStr);
            ShareItemData.MItemList = JsonConvert.DeserializeObject<List<ManualItem>>(ItemStr);
            MTypeAllCheckBoxVInfo CBInfo = JsonConvert.DeserializeObject<MTypeAllCheckBoxVInfo>(CBStr);
            SetMPageRecordCheckBoxUI(CBInfo);
            RenderManualBoardUI(AssemblyShareData.MSectionList);
            RanderManualItemUIData();
        }

        //手动模式 查看记录 设置复选框UI
        public void SetMPageRecordCheckBoxUI(MTypeAllCheckBoxVInfo CBInfo)
        {
            MGPInverBox.Checked = CBInfo.MGPInverF;
            MRPOverstBoardBox.Checked = CBInfo.MRPOverstBoardF;
            MGPOverspBoardBox.Checked = CBInfo.MGPOverspBoardF;
            MfangtieLockspBoardBox.Checked = CBInfo.MfangtieLockspBoardF;
            MRPAddTeethBox.Checked = CBInfo.MRPAddTeethF;
            MRPScrewBox.Checked = CBInfo.MRPScrewF;
            MEGPCheckBox.Checked = CBInfo.MEGPF;
        }

        //查看记录时 渲染零件数据
        public void RecordItemDataRenderUI(List<LabourSingleItem> ItemList)
        {
            if (ItemDataGridView.Rows.Count > 0)
                ItemDataGridView.Rows.Clear();
            for (int i = 0; i < ItemList.Count; i++)
            {
                DataGridView ItemData = new DataGridView();
                int rowIndex = ItemDataGridView.Rows.Add(ItemData);
                ItemDataGridView.Rows[rowIndex].Cells["decRItem"] = new DXButtonCell("-");
                ItemDataGridView.Rows[rowIndex].Cells["ItemUID"].Value = ItemList[i].ItemUID;
                ItemDataGridView.Rows[rowIndex].Cells["ItemName"].Value = ItemList[i].ItemName;
                ItemDataGridView.Rows[rowIndex].Cells["Dim"].Value = ItemList[i].ItemDim;
                ItemDataGridView.Rows[rowIndex].Cells["TheoryL"].Value = ItemList[i].ItemL;
                ItemDataGridView.Rows[rowIndex].Cells["ActL"].Value = ItemList[i].CGItemL;
                ItemDataGridView.Rows[rowIndex].Cells["Num"].Value = ItemList[i].ItemNum;
                ItemDataGridView.Rows[rowIndex].Cells["Remark"].Value = ItemList[i].UIRemark;
            }
        }

        //平面图按钮识别
        private void IdentifyTopDrawBtn_Click(object sender, EventArgs e)
        {
            RecognizeUtils.RemCustomerDWGDoc();
            StandardShareScopeItemParam.ClearStandardScopeData();
            this.WindowState = FormWindowState.Minimized;
            RecognizeUtils.IdentifyStep();
        }

        // 选中花式 根据板 顺序 重新初始化 只显示板名
        public void AutoPageResetBoardDataByCategory(List<StandardCategoryBoard> paramslist)
        {
            //Scene Oper Data
            AssemblyShareData.AUIBlueSectionList = new List<BoardSectionItem>();
            AssemblyShareData.ASectionList = new List<BoardSectionItem>();
            //Clear Item
            ShareItemData.ItemList = new List<SingleItem>();
            ShareItemData.UIItemList = new List<SingleItem>();
            ShareItemData.SurplusItemList = new List<LabourSingleItem>();
            ShareItemData.UISurplusItemList = new List<LabourSingleItem>();
            List<BoardSectionItem> BSList = AssemblyShareData.AUIBlueSectionList;

            if (BoardDataGridView.Rows.Count > 0)
                BoardDataGridView.Rows.Clear();
            if(ItemDataGridView.Rows.Count > 0)
                ItemDataGridView.Rows.Clear();
            if (SurplusItemDataGridView.Rows.Count > 0)
                SurplusItemDataGridView.Rows.Clear();

            if (paramslist != null)
            {
                if(paramslist.Count > 0)
                {
                    for(int i = 0; i < paramslist.Count; i++)
                    {
                        BoardSectionItem BItem = new BoardSectionItem();
                        int FirstIndex = paramslist.FindIndex(item => item.boardCode.Equals(paramslist[i].boardCode));
                        BItem.BoardCode = paramslist[i].boardCode;
                        BItem.BoardName = paramslist[i].boardName;
                        BItem.plateLineNo = paramslist[i].sortNum;
                        BSList.Add(BItem);
                        DataGridView ItemData = new DataGridView();
                        int rowIndex = BoardDataGridView.Rows.Add(ItemData);
                        BoardDataGridView.Rows[rowIndex].Cells["AddOper"] = new DXButtonCell("+");
                        BoardDataGridView.Rows[rowIndex].Cells["OperSub"] = new DXButtonCell("-");
                        BoardDataGridView.Rows[rowIndex].Cells["BoardCode"].Value = BItem.BoardCode;
                        BoardDataGridView.Rows[rowIndex].Cells["BoardName"].Value = BItem.BoardName;
                        BoardDataGridView.Rows[rowIndex].Cells["PlateNum"].Value = BItem.Num;
                        if (!paramslist[i].boardCode.Equals("fangtie"))
                            BoardDataGridView.Rows[rowIndex].Cells["PlateNum"].ReadOnly = true;
                    }
                }
            }

            for (int i = 0; i < BSList.Count; i++)
            {
                int FBIndex = BSList.FindIndex(item => item.BoardCode.Equals(BSList[i].BoardCode));
                BSList[i].BoardUID = BSList[i].BoardCode + (i - FBIndex);
            }

            AssemblyShareData.ASectionList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(BSList);
        }

        private void DataForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();//窗口隐藏
            e.Cancel = true;//取消关闭
        }

        //+板 多种选择模式 Action
        public void AddBoardOperAction(string BoardCode)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                AutoPageMulOptAddBoardData(BoardCode);
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
            {
                ManualPageMulOptAddBoardData(BoardCode);
                MTypeSetAllItemCosBoardWhenOperBoard();
                MenuShow();
            }
        }

        //自动模式 多选项 添加板数据
        private void AutoPageMulOptAddBoardData(string wantAddBCode)
        {
            List<BoardSectionItem> OperBList = AssemblyShareData.AUIBlueSectionList;
            int OPerUIDIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
            if(OPerUIDIndex != -1)
            {
                BoardSectionItem operB = AssemblyShareData.AUIBlueSectionList[OPerUIDIndex];
                AMTypeCheckWarn checkInfo = ATypeCheckBoardNumBAddBOper(wantAddBCode);
                if (checkInfo.warnF)
                {
                    //操作下针板
                    if (operB.BoardCode.Equals("epBoard"))
                    {
                        //一组上下针板
                        if (wantAddBCode.Equals("epfpBoard"))
                        {
                            int lastepIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                            if (lastepIndex != -1)
                            {
                                //上针板
                                BoardSectionItem fpItem = new BoardSectionItem();
                                fpItem.BoardCode = "fpBoard";
                                fpItem.ManualOperFlag = true;
                                int fpcount = OperBList.FindAll(item => item.BoardCode.Equals("fpBoard")).Count();
                                fpItem.BoardName = CU.SetBoardNameByCode("fpBoard") + fpcount;
                                OperBList.Insert(lastepIndex + 1, fpItem);
                                //下针板
                                BoardSectionItem epItem = new BoardSectionItem();
                                epItem.BoardCode = "fpBoard";
                                epItem.ManualOperFlag = true;
                                int epcount = OperBList.FindAll(item => item.BoardCode.Equals("epBoard")).Count();
                                epItem.BoardName = CU.SetBoardNameByCode("epBoard") + epcount;
                                OperBList.Insert(lastepIndex + 2, epItem);
                            }
                        }
                        else
                        {
                            BoardSectionItem otherItem = new BoardSectionItem();
                            otherItem.BoardCode = wantAddBCode;
                            int bcount = OperBList.FindAll(item => item.BoardCode.Equals(wantAddBCode)).Count();
                            if(bcount != 0)
                                otherItem.BoardName = CU.SetBoardNameByCode(wantAddBCode) + bcount;
                            else
                                otherItem.BoardName = CU.SetBoardNameByCode(wantAddBCode);
                            otherItem.BoardUID = wantAddBCode + bcount;
                            otherItem.ManualOperFlag = true;
                            OperBList.Insert(OPerUIDIndex + 1, otherItem);
                        }
                    }
                    else
                    {
                        OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
                        List<string> SecondCheckBCodeList = new List<string> { "hsBoard", "sfangtie", "hrBoard", "mpBoard" };
                        Boolean optionAFlag = SecondCheckBCodeList.Contains(wantAddBCode);
                        if (!optionAFlag)
                        {
                            BoardSectionItem Item = new BoardSectionItem();
                            Item.BoardCode = wantAddBCode;
                            Item.ManualOperFlag = true;
                            int BoardLastIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals(wantAddBCode));
                            int OperBIndex = OperBList.FindLastIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                            if (BoardLastIndex != -1)
                            {
                                BoardSectionItem BeforeItem = OperBList[BoardLastIndex];
                                //人为加上序号
                                if (BeforeItem.BoardCode.Equals(wantAddBCode))
                                {
                                    int count = OperBList.FindAll(item => item.BoardCode.Equals(wantAddBCode)).Count();
                                    Item.BoardUID = BeforeItem.BoardCode + count;
                                    if (count != 0)
                                        Item.BoardName = CU.SetBoardNameByCode(BeforeItem.BoardCode) + count;
                                    else
                                        Item.BoardName = CU.SetBoardNameByCode(BeforeItem.BoardCode);
                                }
                                OperBList.Insert(BoardLastIndex + 1, Item);
                            }
                            //比如A板下面加了块推板
                            else
                            {
                                string targetBoardCode = Item.BoardCode;
                                int count = OperBList.FindAll(item => item.BoardCode.Equals(targetBoardCode)).Count();
                                Item.BoardUID = targetBoardCode + count;
                                Item.BoardName = CU.SetBoardNameByCode(targetBoardCode);
                                OperBList.Insert(CADCommonForm.autoOperBoardIndex + 1, Item);
                            }
                        }
                        else
                        {
                            BoardSectionItem Item = new BoardSectionItem();
                            Item.BoardCode = wantAddBCode;
                            if (wantAddBCode.Equals("sfangtie"))
                                Item.Num = 2;
                            int count = OperBList.FindAll(item => item.BoardCode.Equals(wantAddBCode)).Count();
                            Item.ManualOperFlag = true;
                            int BCount = OperBList.FindAll(item => item.BoardCode.Equals(Item.BoardCode)).Count();
                            if (BCount != 0)
                                Item.BoardName = CU.SetBoardNameByCode(wantAddBCode) + BCount;
                            else
                                Item.BoardName = CU.SetBoardNameByCode(wantAddBCode);
                            Item.BoardUID = Item.BoardCode + BCount;
                            int OperBIndex = OperBList.FindLastIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                            OperBList.Insert(OperBIndex + 1, Item);
                        }
                    }

                    //调整PlateNo
                    for (int i = 0; i < OperBList.Count; i++)
                        OperBList[i].plateLineNo = i + 1;

                    AssemblyShareData.AUIBlueSectionList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(OperBList);
                    AssemblyShareData.ASectionList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(OperBList);
                    AutoPageRenderBoardUIData(RenderType.UserOper);
                }
                else
                    MessageBox.Show(checkInfo.tig);
            } 
        }

        //手动模式 多选项 添加板数据
        private void ManualPageMulOptAddBoardData(string wantAddBCode)
        {
            //Check Board Num
            List<ManualBoardItem> BlueBList = AssemblyShareData.MSectionList;
            List<string> firstCheckBCodeList = new List<string> { "aBoard", "bBoard", "stBoard",
                "rspBoard", "spBoard" };
            if (firstCheckBCodeList.Contains(wantAddBCode))
            {
                int BCount = BlueBList.FindAll(item => item.BoardCode.Equals(BoardCode)).ToList().Count();
                if (BCount == 3)
                {
                    string BName = CU.SetBoardNameByCode(wantAddBCode);
                    MessageBox.Show(BName + "数量不能超过3块 请校验!");
                    return;
                }
            }
            List<ManualBoardItem> OperBList = AssemblyShareData.MSectionList;
            OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
            List<string> SecondCheckBCodeList = new List<string> { "hsBoard", "sfangtie", "hrBoard", "mpBoard" };
            Boolean optionAFlag = SecondCheckBCodeList.Contains(wantAddBCode);
            if (!optionAFlag)
            {
                ManualBoardItem Item = new ManualBoardItem();
                Item.BoardCode = wantAddBCode;
                Item.ManualOperFlag = true;
                int BoardLastIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals(wantAddBCode));
                int OperBIndex = OperBList.FindLastIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                if (BoardLastIndex != -1)
                {
                    ManualBoardItem BeforeItem = OperBList[BoardLastIndex];
                    //人为加上序号
                    if (BeforeItem.BoardCode.Equals(wantAddBCode))
                    {
                        int count = OperBList.FindAll(item => item.BoardCode.Equals(wantAddBCode)).Count();
                        Item.BoardUID = BeforeItem.BoardCode + count;
                        if (count != 0)
                            Item.BoardName = CU.SetBoardNameByCode(BeforeItem.BoardCode) + count;
                        else
                            Item.BoardName = CU.SetBoardNameByCode(BeforeItem.BoardCode);
                    }
                    MTypeSetBoardWLLogic(Item);
                    OperBList.Insert(BoardLastIndex + 1, Item);
                }
                //比如A板下面加了块推板
                else
                {
                    Item.BoardName = CU.SetBoardNameByCode(Item.BoardCode);
                    MTypeSetBoardWLLogic(Item);
                    OperBList.Insert(CADCommonForm.mOperBoardIndex + 1, Item);
                }
                for (int i = 0; i < OperBList.Count; i++)
                    OperBList[i].plateLineNo = i + 1;

                AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                ResetMBoardUID();
                MTypeCheckOpetionLogic();
                RenderManualBoardUI(AssemblyShareData.MSectionList);
            }
            else
            {
                ManualBoardItem Item = new ManualBoardItem();
                Item.BoardCode = wantAddBCode;
                int count = OperBList.FindAll(item => item.BoardCode.Equals(wantAddBCode)).Count();
                Item.ManualOperFlag = true;
                int BCount = OperBList.FindAll(item => item.BoardCode.Equals(Item.BoardCode)).Count();
                if (BCount != 0)
                    Item.BoardName = CU.SetBoardNameByCode(wantAddBCode) + BCount;
                else
                    Item.BoardName = CU.SetBoardNameByCode(wantAddBCode);
                MTypeSetBoardWLLogic(Item);
                int OperBIndex = OperBList.FindLastIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                OperBList.Insert(OperBIndex + 1, Item);

                for (int i = 0; i < OperBList.Count; i++)
                    OperBList[i].plateLineNo = i + 1;

                AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                ResetMBoardUID();
                RenderManualBoardUI(AssemblyShareData.MSectionList);
            }
        }
        
        //按标准 补 特殊板宽 方铁&上下针板
        private void MTypeSetFEPFPBoardWLogic(ManualBoardItem Item)
        {
            if (Item.BoardCode.Equals("fangtie") || Item.BoardCode.Equals("epBoard") || Item.BoardCode.Equals("fpBoard"))
            {
                double? BW = MTypeSetBoardArgWhenAddBoard(Item.BoardName);
                if (BW != null)
                    Item.PlateWidth = (double)BW;
            }
        }

        //手动模式 +板操作 根据板Code 型号大小 补充板长 宽 逻辑
        private void MTypeSetBoardWLLogic(ManualBoardItem Item)
        {
            string MouldStr = this.MoldSizeBox.Text;
            string LStr = MouldStr.Substring(2, MouldStr.Length - 2) + "0";
            Item.PlateLength = double.Parse(LStr);
            if (Item.BoardCode.Equals("fangtie") || Item.BoardCode.Equals("epBoard") || Item.BoardCode.Equals("fpBoard"))
            {
                double? BW = MTypeSetBoardArgWhenAddBoard(Item.BoardName);
                if (BW != null)
                    Item.PlateWidth = (double)BW;
            }
            else
            {
                string WStr = MouldStr.Substring(0, 2) + "0";
                Item.PlateWidth = double.Parse(WStr);
            }
        }

        //手动模式 +板操作 根据板Code 型号大小 补充板参数
        private double? MTypeSetBoardArgWhenAddBoard(string BoardName)
        {
            double? Res = null;
            string MouldSeries = null;
            if (CADCommonForm.MoldTypeStr.Equals("PP"))
                MouldSeries = "细水口";
            if (CADCommonForm.MoldTypeStr.Equals("SG"))
                MouldSeries = "大水口";
            if (CADCommonForm.MoldTypeStr.Equals("TP"))
                MouldSeries = "简化型";
            string MouldStr = this.MoldSizeBox.Text;
            string widthStr = MouldStr.Substring(0, 2);
            Boolean moldSizeF = int.TryParse(widthStr, out int WmoldSize);
            if (moldSizeF)
            {
                int realWSize = WmoldSize * 100;
                List<StandBoardWidth>  targetWList = ParamsConfigData.StandardBoardWidthList.FindAll(item => item.series.Equals(MouldSeries)
                && item.xinhao == realWSize);
                if(targetWList.Count > 0)
                {
                    int wIndex = targetWList.FindIndex(item => BoardName.Contains(item.name));
                    if (wIndex != -1)
                        Res = targetWList[wIndex].W;
                }
                else
                {
                    //非标
                    //靠近的标准的方铁
                    if (BoardName.Contains("方铁"))
                    {
                        int nearMoldSize = ComputedUtils.GetMNearMoldSize(MouldStr);
                        if(nearMoldSize != -1)
                        {
                            string nearW = nearMoldSize.ToString().Substring(0, 2);
                            double nearWSize = double.Parse(nearW) * 100;
                            List<StandBoardWidth> wantFWList = ParamsConfigData.StandardBoardWidthList.FindAll(
                                item => item.series.Equals(MouldSeries) && item.xinhao == nearWSize);
                            if (wantFWList.Count > 0)
                            {
                                int wIndex = wantFWList.FindIndex(item => BoardName.Contains(item.name));
                                if (wIndex != -1)
                                    Res = wantFWList[wIndex].W;
                            }
                        } 
                    }
                    if(BoardName.Contains("上针板") || BoardName.Contains("下针板"))
                    {
                        double realMouldSize =  double.Parse(MouldStr);
                        //针板宽度= W -方铁宽度 * 2 - 4（5070以上模架减去10）
                        int diffW = 4;
                        if (realMouldSize >= 5070)
                            diffW = 10;
                        int fIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        if(fIndex != -1)
                        {
                            int refW = WmoldSize * 10;
                            Res = refW - AssemblyShareData.MSectionList[fIndex].PlateThick * - diffW;
                        }
                    }
                }
            }
            return Res;
        }

        //板数据表格鼠标按下事件
        private void BoardDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            int targetIndex = e.RowIndex;
            CADCommonForm.autoOperBoardIndex = e.RowIndex;
            string ViewOperName = BoardDataGridView.Columns[e.ColumnIndex].Name;
            if (ViewOperName.Equals("AddOper") || ViewOperName.Equals("OperSub"))
                AutoBoardAddOrSubOper(ViewOperName);
            if (ViewOperName.Equals("BoardDrawOper"))
                DrawLBThickAndWidth(e.RowIndex);
        }

        //自动模式 接单测量 板厚&长
        public void DrawLBThickAndWidth(int targetIndex)
        {
            this.WindowState = FormWindowState.Minimized;
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            SetFocus(doc.Window.Handle);
            Database db = doc.Database;
            Editor editor = doc.Editor;
            string tigName = null;
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                 tigName = BoardDataGridView.Rows[targetIndex].Cells["BoardName"].Value.ToString();
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                tigName = ManualBoardGridView.Rows[targetIndex].Cells["MBoardName"].Value.ToString();
            editor.WriteMessage("点选" + tigName + "宽厚外轮廓特征线段");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = ZwSoft.ZwCAD.ApplicationServices.Application
                    .DocumentManager.MdiActiveDocument.LockDocument();
                try
                {
                    List<MixedCAD_Line> targetList = new List<MixedCAD_Line>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction transaction = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is Line line)
                                    {
                                        MixedCAD_Line temp = new MixedCAD_Line();
                                        temp.StartPoint.CustomerPoint.X = line.StartPoint.X;
                                        temp.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                                        temp.EndPoint.CustomerPoint.X = line.EndPoint.X;
                                        temp.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                                        temp = RecognizeUtils.TransCADItemLineData(temp);
                                        targetList.Add(temp);
                                    }
                                }
                            }
                        }

                        if(targetList.Count > 0)
                        {
                            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                            {
                                List<MixedCAD_Line> XList = targetList.FindAll(item => item.LineType == CADLineType.XDirLine);
                                List<MixedCAD_Line> YList = targetList.FindAll(item => item.LineType == CADLineType.YDirLine);
                                if (YList.Count > 0)
                                {
                                    List<double> xList = YList.Select(item => item.StartPoint.CustomerPoint.X).ToList();
                                    double maxX = xList.Max();
                                    double minX = xList.Min();
                                    AssemblyShareData.AUIBlueSectionList[targetIndex].PlateWidth = Math.Round(maxX - minX, 0);
                                    BoardDataGridView.Rows[targetIndex].Cells["PlateWidth"].Value = AssemblyShareData.AUIBlueSectionList[targetIndex].PlateWidth;
                                    BoardDataGridView.Rows[targetIndex].Cells["PlateWidth"].Style.BackColor = Color.LightGray;
                                }

                                if (XList.Count > 0)
                                {
                                    List<double> yList = XList.Select(item => item.StartPoint.CustomerPoint.Y).ToList();
                                    double maxY = yList.Max();
                                    double minY = yList.Min();
                                    //Keep 2 decimal places
                                    AssemblyShareData.AUIBlueSectionList[targetIndex].PlateThick = Math.Round(maxY - minY, 2);
                                    BoardDataGridView.Rows[targetIndex].Cells["PlateThick"].Value = AssemblyShareData.AUIBlueSectionList[targetIndex].PlateThick;
                                    BoardDataGridView.Rows[targetIndex].Cells["PlateThick"].Style.BackColor = Color.LightGray;
                                }
                            }

                            if(AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                            {
                                List<MixedCAD_Line> XList = targetList.FindAll(item => item.LineType == CADLineType.XDirLine);
                                List<MixedCAD_Line> YList = targetList.FindAll(item => item.LineType == CADLineType.YDirLine);
                                if (YList.Count > 0)
                                {
                                    List<double> xList = YList.Select(item => item.StartPoint.TransSplitPoint.X).ToList();
                                    double maxX = xList.Max();
                                    double minX = xList.Min();
                                    AssemblyShareData.MSectionList[targetIndex].PlateWidth = Math.Round(maxX - minX, 0);
                                    ManualBoardGridView.Rows[targetIndex].Cells["MPlateWidth"].Value = AssemblyShareData.MSectionList[targetIndex].PlateWidth;
                                    ManualBoardGridView.Rows[targetIndex].Cells["MPlateWidth"].Style.BackColor = Color.LightGray;
                                }

                                if (XList.Count > 0)
                                {
                                    List<double> yList = XList.Select(item => item.StartPoint.TransSplitPoint.Y).ToList();
                                    double maxY = yList.Max();
                                    double minY = yList.Min();
                                    //Keep 2 decimal places
                                    AssemblyShareData.MSectionList[targetIndex].PlateThick = Math.Round(maxY - minY, 2);
                                    ManualBoardGridView.Rows[targetIndex].Cells["MPlateThick"].Value = AssemblyShareData.MSectionList[targetIndex].PlateThick;
                                    ManualBoardGridView.Rows[targetIndex].Cells["MPlateThick"].Style.BackColor = Color.LightGray;
                                }
                            }
                           
                        }                     
                        transaction.Commit();
                        doc.Editor.Regen();
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                    MenuShow();
                }
            }
            else
            {

            }
        }

        //自动模式 +板时 检测板数量
        public AMTypeCheckWarn ATypeCheckBoardNumBAddBOper(string cbCode)
        {
            AMTypeCheckWarn Res = new AMTypeCheckWarn();
            List<BoardSectionItem> OperBList = AssemblyShareData.AUIBlueSectionList;
            Boolean fpF = cbCode.Equals("fpBoard");
            Boolean epF = cbCode.Equals("epBoard");
            Boolean epffpF = cbCode.Equals("epfpBoard");
            if (epF || fpF)
            {
                Boolean BCountF = OperBList.FindAll(item => item.BoardCode.Equals(cbCode)).ToList().Count == 2;
                if(BCountF)
                {
                    Res.warnF = false;
                    if(fpF)
                        Res.tig = "上针板数量已达上限(2) 无法继续+ !";
                    if(epF)
                        Res.tig = "下针板数量已达上限(2) 无法继续+ !";
                }
            }
            if (epffpF)
            {
                Boolean fpCountF = OperBList.FindAll(item => item.BoardCode.Equals("fpBoard")).ToList().Count == 2;
                Boolean epCountF = OperBList.FindAll(item => item.BoardCode.Equals("epBoard")).ToList().Count == 2;
                if(fpCountF || epCountF)
                {
                    Res.warnF = false;
                    if(fpCountF)
                        Res.tig += "上针板数量已达上限(2) ";
                    if (epCountF)
                        Res.tig += "下针板数量已达上限(2) ";
                    Res.tig += "无法继续!";
                }
            }
            else
            {
                List<string> firstCheckBCodeList = new List<string> { "aBoard", "bBoard", "stBoard", "rspBoard", "spBoard" };
                if (firstCheckBCodeList.Contains(cbCode))
                {
                    int BCount = OperBList.FindAll(item => item.BoardCode.Equals(BoardCode)).ToList().Count();
                    if (BCount == 3)
                    {
                        string BName = CU.SetBoardNameByCode(cbCode);
                        Res.tig = BName + "数量不能超过3块 请校验!";
                    }
                }
            }
            return Res;
        }

        //自动模式 +-板操作
        private void AutoBoardAddOrSubOper(string ViewOperName)
        {
            int operIndex = CADCommonForm.autoOperBoardIndex;
            List<BoardSectionItem> CheckBList = AssemblyShareData.ASectionList;
            List<BoardSectionItem> OperBList = AssemblyShareData.AUIBlueSectionList;
            //操作之前校验是否有识别写数据 报提示
            //Boolean F = CheckBList.FindIndex(item => item.ReFlag) != -1;
            //if (F)
            //{
            //    MessageBox.Show(UserPromptErrorType.OperBoardError);
            //    return;
            //}
            //动态设置板选项
            BSForm.SelectBoardComboBox.DataSource = null;
            //当前板
            NowOperBoardUID = OperBList[operIndex].BoardUID;
            string NowOperBoardCode = OperBList[operIndex].BoardCode;
            if (ViewOperName.Equals("AddOper"))
            {
                if (NowOperBoardUID != null)
                {
                    List<string> addBCList = new List<string>();
                    List<string> MulBCodeList = new List<string>() { "tpBoard", "cpBoard", "aBoard", "stBoard", "bBoard", "spBoard", "epBoard" };
                    int lepIndex = OperBList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
                    //底板的前一块板 强制有2个选项
                    Boolean SLF = operIndex == lepIndex - 1;
                    if (SLF)
                    {
                        addBCList.Add("mpBoard");
                        addBCList.Add("hrBoard");
                    }
                    Boolean SampleF = !MulBCodeList.Contains(NowOperBoardCode);
                    //单选项
                    if (SampleF)
                    {
                        if (NowOperBoardCode.Equals("rspBoard"))
                            addBCList.Add("rspBoard");
                        if (NowOperBoardCode.Equals("fpBoard"))
                            addBCList.Add("fpBoard");
                        //针对底板
                        if (NowOperBoardCode.Equals("bpBoard"))
                            addBCList.Add("sepBoard");
                    }
                    //多选项
                    else
                    {
                        List<DataGirdViewBoardItem> DGBList = new List<DataGirdViewBoardItem>();
                        if (NowOperBoardCode.Equals("epBoard"))
                        {
                            addBCList.Add("epBoard");
                            addBCList.Add("epfpBoard");
                            addBCList.Add("mpBoard");
                            addBCList.Add("hnpBoard");
                        }

                        if (NowOperBoardCode.Equals("tpBoard"))
                        {
                            int aBoardFirstIndex = OperBList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                            if (aBoardFirstIndex != -1)
                            {
                                addBCList.Add("sfangtie");
                                addBCList.Add("hrBoard");
                                addBCList.Add("mpBoard");
                            }
                        }

                        if (NowOperBoardCode.Equals("cpBoard"))
                        {
                            int aBoardFirstIndex = OperBList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                            if (aBoardFirstIndex != -1)
                            {
                                addBCList.Add("sfangtie");
                                addBCList.Add("hrBoard");
                                addBCList.Add("mpBoard");
                            }
                        }



                        if (NowOperBoardCode.Equals("aBoard"))
                        {
                            addBCList.Add("aBoard");
                            Boolean ExitsfangtieFlag = OperBList.FindIndex(item => item.BoardCode.Equals("sfangtie")) != -1;
                            //有上方铁
                            //if (ExitsfangtieFlag)
                            //{
                            //    addBCList.Add("epBoard");
                            //    addBCList.Add("fpBoard");
                            //}
                            addBCList.Add("mpBoard");
                            addBCList.Add("stBoard");
                        }

                        if (NowOperBoardCode.Equals("stBoard"))
                        {
                            addBCList.Add("stBoard");
                            addBCList.Add("mpBoard");
                        }

                        if (NowOperBoardCode.Equals("bBoard"))
                        {
                            addBCList.Add("bBoard");
                            addBCList.Add("mpBoard");
                        }

                        if (NowOperBoardCode.Equals("spBoard"))
                        {
                            addBCList.Add("spBoard");
                            addBCList.Add("mpBoard");
                        } 
                    }

                    if (addBCList.Count > 0)
                        addBCList = addBCList.Distinct().ToList();

                    if (addBCList.Count > 0)
                    {
                        //Single Board Type
                        if(addBCList.Count == 1)
                        {
                            AMTypeCheckWarn checkInfo = ATypeCheckBoardNumBAddBOper(NowOperBoardCode);
                            if (checkInfo.warnF)
                            {
                                Boolean OperfPF = NowOperBoardCode.Equals("fpBoard");
                                //上针板 ->上针板1
                                if (OperfPF)
                                    OperBList[operIndex].BoardName = CU.SetBoardNameByCode(NowOperBoardCode) + 1;

                                string toaddBCode = addBCList[0];
                                BoardSectionItem Item = new BoardSectionItem();
                                int count = OperBList.FindAll(item => item.BoardCode.Equals(toaddBCode)).Count();
                                Item.BoardUID = toaddBCode + count;
                                Item.BoardCode = toaddBCode;
                                string BName = CU.SetBoardNameByCode(toaddBCode);
                                if (count != 0)
                                {
                                    if (!OperfPF)
                                        Item.BoardName = BName + count;
                                    else
                                        Item.BoardName = BName;
                                }
                                else
                                    Item.BoardName = BName;

                                Item.ManualOperFlag = true;
                                Boolean sepBoardF = Item.BoardCode.Equals("sepBoard");
                                if (sepBoardF)
                                {
                                    int bpIndex = OperBList.FindIndex(item => item.BoardCode.Equals("bpBoard"));
                                    OperBList.Insert(bpIndex, Item);
                                }
                                else
                                    OperBList.Insert(operIndex + 1, Item);

                                for (int i = 0; i < OperBList.Count; i++)
                                    OperBList[i].plateLineNo = i + 1;

                                AssemblyShareData.AUIBlueSectionList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(OperBList);
                                AssemblyShareData.ASectionList = (List<BoardSectionItem>)ConvertUtils.DeepCopyObject(OperBList);
                                AutoPageRenderBoardUIData(RenderType.UserOper);
                            }
                            else
                                MessageBox.Show(checkInfo.tig);
                        }
                        //Mul Board Type
                        else
                        {
                            List<DataGirdViewBoardItem> DGBList = new List<DataGirdViewBoardItem>();
                            for (int i = 0; i < addBCList.Count; i++)
                            {
                                DataGirdViewBoardItem DGVBItem = new DataGirdViewBoardItem(addBCList[i], CU.SetBoardNameByCode(addBCList[i]));
                                DGBList.Add(DGVBItem);
                            }
                            BSForm.SelectBoardComboBox.DisplayMember = "BoardName";
                            BSForm.SelectBoardComboBox.ValueMember = "BoardCode";
                            BSForm.SelectBoardComboBox.DataSource = DGBList;
                            ZwSoft.ZwCAD.ApplicationServices.Application.ShowModelessDialog(BSForm);
                        }
                    }

                }
            }
            //-板操作 1.手动+ 可以删掉 2.原花式基础上 针板和方铁可以删掉，其它不删
            if (ViewOperName.Equals("OperSub"))
            {
                if (NowOperBoardCode.Equals("fangtie"))
                {
                    //方铁&=1 连同针板一起删掉
                    int FCount = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals("fangtie")).Count;
                    if (FCount == 1)
                    {
                        List<BoardSectionItem> fpBList = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals("fpBoard"));
                        List<BoardSectionItem> epBList = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals("epBoard"));
                        for (int i = 0; i < fpBList.Count; i++)
                        {
                            int FI = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(fpBList[i].BoardUID));
                            AssemblyShareData.AUIBlueSectionList.RemoveAt(FI);
                        }
                        for (int i = 0; i < epBList.Count; i++)
                        {
                            int FI = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(epBList[i].BoardUID));
                            AssemblyShareData.AUIBlueSectionList.RemoveAt(FI);
                        }
                        AssemblyShareData.AUIBlueSectionList = AssemblyShareData.AUIBlueSectionList.FindAll(item => !item.BoardCode.Equals("fangtie"));
                    }
                    else
                    {
                        int NowBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                        AssemblyShareData.AUIBlueSectionList.RemoveAt(NowBIndex);
                        //对方铁UID进行二次调整
                        List<BoardSectionItem> ToCUIDBList = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals(NowOperBoardCode));
                        if (ToCUIDBList.Count > 0)
                        {
                            int BReSetNo = 0;
                            for (int i = 0; i < ToCUIDBList.Count; i++)
                            {
                                AssemblyShareData.AUIBlueSectionList[i].BoardUID = AssemblyShareData.AUIBlueSectionList[i].BoardCode + BReSetNo;
                                if (BReSetNo == 0)
                                    AssemblyShareData.AUIBlueSectionList[i].BoardName = "方铁";
                                else
                                    AssemblyShareData.AUIBlueSectionList[i].BoardName = "方铁" + BReSetNo;
                                BReSetNo++;
                            }
                        }
                    }
                    if (AssemblyShareData.AUIBlueSectionList != null)
                    {
                        for (int i = 0; i < AssemblyShareData.AUIBlueSectionList.Count; i++)
                            AssemblyShareData.AUIBlueSectionList[i].plateLineNo = i + 1;
                        AutoPageRenderBoardUIData(RenderType.UserOper);
                    }
                }
                else
                {
                    int OPerBUIDIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                    Boolean MFlag = AssemblyShareData.AUIBlueSectionList[OPerBUIDIndex].ManualOperFlag;
                    int NowBCount = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals(NowOperBoardCode)).Count;
                    string BoardName = CU.SetBoardNameByCode(NowOperBoardCode);
                    List<string> CheckBCodeList = new List<string> { "fpBoard", "epBoard" };
                    Boolean CanDelCodeF = CheckBCodeList.Contains(NowOperBoardCode);
                    if (MFlag || CanDelCodeF)
                    {
                        int NowBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                        AssemblyShareData.AUIBlueSectionList.RemoveAt(NowBIndex);
                        if (AssemblyShareData.AUIBlueSectionList != null)
                        {
                            for (int i = 0; i < AssemblyShareData.AUIBlueSectionList.Count; i++)
                                AssemblyShareData.AUIBlueSectionList[i].plateLineNo = i + 1;
                            AutoPageRenderBoardUIData(RenderType.UserOper);
                        }
                    }
                    else
                    {
                        MessageBox.Show(UserPromptErrorType.CannotDelBoardError);
                        return;
                    }
                }
            }
        }

        //板下拉选项
        public class DataGirdViewBoardItem
        {
            public DataGirdViewBoardItem(string boardCode, string boardName)
            {
                BoardCode = boardCode;
                BoardName = boardName;
            }
            public string BoardCode { set; get; }
            public string BoardName { set; get; }
        }

        //DataGridView 零件 下拉选项
        public class DataGridViewItemItem
        {
            public DataGridViewItemItem(string itemName, string itemCode)
            {
                ItemName = itemName;
                ItemCode = itemCode;
            }
            public string ItemName { get; set; }
            public string ItemCode { get; set; }
        }
     
        //接单测量 零件 直径Dim
        public  void MeasureDWGItemDim(int targetIndex,string OperType)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            SetFocus(doc.Window.Handle);
            Database db = doc.Database;
            // 获取编辑器和选择集
            Editor editor = doc.Editor;
            //editor.SelectAll();
            string tigName = null;
            if(OperType.Equals("AUTOAUTO"))
                tigName = ItemDataGridView.Rows[targetIndex].Cells["ItemName"].Value.ToString();
            if (OperType.Equals("AUTOM"))
                tigName = SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemName"].Value.ToString();
            if (OperType.Equals("M"))
                tigName = ManualItemGridView.Rows[targetIndex].Cells["MItemName"].Value.ToString();
            editor.SetImpliedSelection(new ObjectId[] { });
            editor.WriteMessage("点选" + tigName  + "直径特征线段");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    List<double> pxList = new List<double>();
                    List<double> pyList = new List<double>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction transaction = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is Line line)
                                    {
                                        pxList.Add(line.StartPoint.X);
                                        pxList.Add(line.EndPoint.X);
                                        pyList.Add(line.StartPoint.Y);
                                        pyList.Add(line.EndPoint.Y);
                                    }
                                }
                            }
                        }
                        if (pxList.Count > 0)
                        {
                            //只需要知道Dim 推算出规格
                            double minX = pxList.Min();
                            double maxX = pxList.Max();
                            double minLabelY = pyList.Min();
                            double maxLabelY = pyList.Max();
                            double labelPosY = (maxLabelY - minLabelY) * 0.2 + minLabelY;
                            Point3d labelPoint1 = new Point3d(minX, labelPosY, 0);
                            Point3d labelPoint2 = new Point3d(maxX, labelPosY, 0);
                            double Dim = Math.Round(maxX - minX, 0);
                            CADAuxiliaryUtils.DrawTwoLineLabel(labelPoint1, labelPoint2, 0,0);
                            //自动模式 自动识别出的零件
                            if (OperType.Equals("AUTOAUTO"))
                            {
                                Object targetRow = ItemDataGridView.Rows[targetIndex].Cells["Dim"].Value;
                                if (targetRow != null)
                                {
                                    Boolean F = Double.TryParse(targetRow.ToString(), out double resDim);
                                    if (F)
                                        if (resDim == 0)
                                            ItemDataGridView.Rows[targetIndex].Cells["Dim"].Value = Dim;
                                }
                                else
                                    ItemDataGridView.Rows[targetIndex].Cells["Dim"].Value = Dim;
                                ItemDataGridView.Rows[targetIndex].Cells["ItemOperMDim"].Value = Dim;
                                ItemDataGridView.Rows[targetIndex].Cells["ItemOperMDim"].Style.BackColor = Color.LightGray;
                            }
                            //自动模式 手动补充的零件
                            if (OperType.Equals("AUTOM"))
                            {
                                SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemDim"].Value = Dim;
                                SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemDim"].Style.BackColor = Color.LightGray;
                            }
                            //手动模式 设置UI & 值
                            if (OperType.Equals("M"))
                            {
                                ShareItemData.MItemList[targetIndex].MDim = Dim;
                                Object targetRow = ManualItemGridView.Rows[targetIndex].Cells["MItemDim"].Value;
                                if (targetRow != null)
                                {
                                    Boolean F = Double.TryParse(targetRow.ToString(), out double resDim);
                                    if (F)
                                    {
                                        if (resDim == 0)
                                        {
                                            ShareItemData.MItemList[targetIndex].Dim = resDim;
                                            ManualItemGridView.Rows[targetIndex].Cells["MItemDim"].Value = Dim;
                                        }
                                    }
                                }
                                else
                                {
                                    ShareItemData.MItemList[targetIndex].Dim = Dim;
                                    ManualItemGridView.Rows[targetIndex].Cells["MItemDim"].Value = Dim;
                                }

                                ManualItemGridView.Rows[targetIndex].Cells["MItemMDim"].Value = Dim;
                            }
                        }
                        transaction.Commit();
                        doc.Editor.Regen();
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                    MenuShow();
                }
            }

        }

        //接单测量 零件 长度L
        public void MeasureDWGItemL(int targetIndex,string OperType)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            SetFocus(doc.Window.Handle);
            Database db = doc.Database;
            // 获取编辑器和选择集
            Editor editor = doc.Editor;
            string tigName = null;
            if (OperType.Equals("AUTOAUTO"))
                tigName = ItemDataGridView.Rows[targetIndex].Cells["ItemName"].Value.ToString();
            if (OperType.Equals("AUTOM"))
                tigName = SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemName"].Value.ToString();
            if (OperType.Equals("M"))
                tigName = ManualItemGridView.Rows[targetIndex].Cells["MItemName"].Value.ToString();
            editor.SetImpliedSelection(new ObjectId[] { });
            editor.WriteMessage("点选"+ tigName + "最高点最低点横线");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    List<double> pyList = new List<double>();
                    List<CAD_Line> lineList = new List<CAD_Line>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            // 获取块表和模型空间
                            BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is Line line)
                                    {
                                        CAD_Line Item = new CAD_Line();
                                        Item.StartPoint.X = line.StartPoint.X;
                                        Item.StartPoint.Y = line.StartPoint.Y;
                                        Item.EndPoint.X = line.EndPoint.X;
                                        Item.EndPoint.Y = line.EndPoint.Y;
                                        Item.Length = line.Length;
                                        lineList.Add(Item);
                                        pyList.Add(line.StartPoint.Y);
                                        pyList.Add(line.EndPoint.Y);
                                    }
                                }
                            }
                            if (pyList.Count > 0)
                            {
                                double length = lineList.Min(item => item.Length);
                                CAD_Line minLTarget = lineList.Find(item => item.Length == length);
                                double targetSX = (minLTarget.StartPoint.X + minLTarget.EndPoint.X) / 2;
                                //只需要知道Dim 推算出规格
                                double minY = pyList.Min();
                                double maxY = pyList.Max();
                                double L = Math.Round(maxY - minY, 0);
                                Point3d MinCP = new Point3d(targetSX, minY, 0);
                                Point3d MaxCP = new Point3d(targetSX, maxY, 0);
                                AlignedDimension ro = new AlignedDimension();
                                ro.XLine1Point = MinCP;
                                ro.XLine2Point = MaxCP;
                                ro.DimLinePoint = new Point3d((MinCP.X + MaxCP.X) / 2, (MinCP.Y + MaxCP.Y) / 2, 0);
                                modelSpace.AppendEntity(ro);
                                tr.AddNewlyCreatedDBObject(ro, true);
                                //自动模式 自动零件
                                if (OperType.Equals("AUTOAUTO"))
                                {
                                    Object targetL = ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value;
                                    if (targetL != null)
                                    {
                                        Boolean F = Double.TryParse(targetL.ToString(), out double resL);
                                        if (F)
                                        {
                                            if (resL == 0)
                                            {
                                                if (tigName.Contains("导柱") || tigName.Contains("导柱"))
                                                    ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = CU.GPLessThan200TheoryLRepRule((int)L);
                                                if (tigName.Contains("套"))
                                                    ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = CU.BushCustomerLTranToTheoryL((int)L);
                                                if (tigName.Contains("回针"))
                                                    ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = ComputedUtils.RPTheoryLRepRule((int)L);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (tigName.Contains("导柱") || tigName.Contains("导柱"))
                                            ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = CU.GPLessThan200TheoryLRepRule((int)L);
                                        if (tigName.Contains("套"))
                                            ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = CU.BushCustomerLTranToTheoryL((int)L);
                                        if (tigName.Contains("回针"))
                                            ItemDataGridView.Rows[targetIndex].Cells["TheoryL"].Value = ComputedUtils.RPTheoryLRepRule((int)L);
                                    }
                                    ItemDataGridView.Rows[targetIndex].Cells["ItemOperMLength"].Value = L;
                                    ItemDataGridView.Rows[targetIndex].Cells["ItemOperMLength"].Style.BackColor = Color.LightGray;
                                }
                                //自动模式 手动零件
                                if (OperType.Equals("AUTOM"))
                                {
                                    SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemLength"].Value = L;
                                    SurplusItemDataGridView.Rows[targetIndex].Cells["SurplusItemLength"].Style.BackColor = Color.LightGray;
                                }
                                //手动模式 零件
                                if (OperType.Equals("M"))
                                {
                                    ShareItemData.MItemList[targetIndex].ML = L;
                                    Object targetL = ManualItemGridView.Rows[targetIndex].Cells["MItemL"].Value;
                                    if (targetL != null)
                                    {
                                        Boolean F = Double.TryParse(targetL.ToString(), out double resL);
                                        if (F)
                                        {
                                            if (resL == 0)
                                            {
                                                ShareItemData.MItemList[targetIndex].L = L;
                                                ManualItemGridView.Rows[targetIndex].Cells["MItemL"].Value = L;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ShareItemData.MItemList[targetIndex].L = L;
                                        ManualItemGridView.Rows[targetIndex].Cells["MItemL"].Value = L;
                                    }

                                    ManualItemGridView.Rows[targetIndex].Cells["MitemML"].Value = L;

                                }
                            }
                            tr.Commit();
                            doc.Editor.Regen();
                        }
                       
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                   MenuShow();
                }
            }
            else
            {

            }
        }

        //识别零件数据表格点击事件
        private void ItemDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string ViewOperName = ItemDataGridView.Columns[e.ColumnIndex].Name;
            string ItemUID = ItemDataGridView.Rows[e.RowIndex].Cells["ItemUID"].Value.ToString();
            string ItemCode = ItemDataGridView.Rows[e.RowIndex].Cells["ItemUID"].Value.ToString();
            //点击了删除零件 删除这条数据
            if (ViewOperName.Equals("decRItem"))
            {
                int dIndex = ShareItemData.UIItemList.FindIndex(item => item.ItemUID.Equals(ItemUID));
                if(dIndex != -1)
                {
                    ShareItemData.UIItemList.RemoveAt(dIndex);
                    ItemDataGridView.Rows.RemoveAt(e.RowIndex);
                }
            }
        }

        //手动补充零件数据表格点击事件
        private void SurplusItemDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string ViewOperName = SurplusItemDataGridView.Columns[e.ColumnIndex].Name;
            if (e.RowIndex >= 0)
            {
                var ItemUIDValue = SurplusItemDataGridView.Rows[e.RowIndex].Cells["SurplusItemUID"].Value;
                if(ItemUIDValue != null)
                    if (ViewOperName.Equals("SubLabourItem"))
                        SurplusItemDataGridView.Rows.RemoveAt(e.RowIndex);
            }
            //点击添加零件
            if (ViewOperName.Equals("AddLabourItem"))
            {
                DataGridViewRow ItemData = new DataGridViewRow();
                int rIndex = SurplusItemDataGridView.Rows.Add(ItemData);
                SurplusItemDataGridView.Rows[rIndex].Cells["AddLabourItem"] = new DXButtonCell("+");
                SurplusItemDataGridView.Rows[rIndex].Cells["SubLabourItem"] = new DXButtonCell("-");
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemUID"].Value = "";
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemName"].Value = "";
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemDim"].Value = 0;
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemLength"].Value = 0;
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemNum"].Value = 0;
                SurplusItemDataGridView.Rows[rIndex].Cells["SurplusItemRemark"].Value = "";
            }
        }


        public void ATypeCollectionRCItemUIData()
        {
            if (ItemDataGridView.Rows.Count == 0)
                ShareItemData.UIItemList = new List<SingleItem>();

            //用户可能在界面上修改了识别零件的数据 需要将界面的数据同步一次
            if (ItemDataGridView.Rows.Count > 0)
            {
                for (int i = 0; i < ItemDataGridView.Rows.Count; i++)
                {
                    string UID = ItemDataGridView.Rows[i].Cells["ItemUID"].Value.ToString();
                    int tIndex = ShareItemData.UIItemList.FindIndex(item => item.ItemUID.Equals(UID));
                    if(tIndex != -1)
                    {
                        var DimValue = ItemDataGridView.Rows[i].Cells["Dim"].Value;
                        if (DimValue != null)
                        {
                            string DimStr = DimValue.ToString();
                            bool DimNumF = int.TryParse(DimStr, out int result);
                            if (DimNumF)
                                ShareItemData.UIItemList[tIndex].Dim = int.Parse(DimStr);
                        }

                        //设置长度
                        var LValue = ItemDataGridView.Rows[i].Cells["TheoryL"].Value;
                        if (LValue != null)
                        {
                            bool LStrNumF = int.TryParse(LValue.ToString(), out int result);
                            if (LStrNumF)
                            {
                                string LStr = LValue.ToString();
                                if (ConvertUtils.JudgeItemTypeIsScrew(ShareItemData.UIItemList[tIndex].ItemNameType))
                                    ShareItemData.UIItemList[tIndex].TheoryScrewH = int.Parse(LStr);

                                if (ConvertUtils.JudgeNoScrewButAboutItem(ShareItemData.UIItemList[tIndex].ItemNameType))
                                {
                                    if (ConvertUtils.JudgeIsGPOrRPItem(ShareItemData.UIItemList[tIndex].ItemNameType))
                                        ShareItemData.UIItemList[tIndex].TheoryH = int.Parse(LStr);
                                    else
                                        ShareItemData.UIItemList[tIndex].RealH = int.Parse(LStr);
                                }

                                if (ConvertUtils.JudgeItemTypeAboutBush(ShareItemData.UIItemList[tIndex].ItemNameType))
                                    ShareItemData.UIItemList[tIndex].RealH = int.Parse(LStr);
                            }
                        }

                        var NumValue = ItemDataGridView.Rows[i].Cells["Num"].Value;
                        if(NumValue != null)
                        {
                            string LStr = NumValue.ToString();
                            bool NumNumF = int.TryParse(LStr, out int result);
                            if (NumNumF)
                                ShareItemData.UIItemList[tIndex].ItemNum = int.Parse(LStr);
                        }
                        
                        var RemarkValue = ItemDataGridView.Rows[i].Cells["Remark"].Value;
                        if (RemarkValue != null)
                            ShareItemData.UIItemList[tIndex].Remark = RemarkValue.ToString();
                    }
                    
                }

            }
        }

        // TO EDIT 
        public void ATypeCollectionLabourItemUIData()
        {
            if (SurplusItemDataGridView.Rows.Count == 0)
                ShareItemData.UISurplusItemList = new List<LabourSingleItem>();
            if (SurplusItemDataGridView.Rows.Count > 0)
            {
                List<LabourSingleItem> tempLList = new List<LabourSingleItem>();
                for (int i = 0; i < SurplusItemDataGridView.Rows.Count; i++)
                {
                    LabourSingleItem LSItem = new LabourSingleItem();
                    var SurplusItemNameValue = SurplusItemDataGridView.Rows[i].Cells["SurplusItemName"].Value;
                    if (SurplusItemNameValue != null)
                        LSItem.ItemName = SurplusItemNameValue.ToString();

                    var SurplusItemDimValue = SurplusItemDataGridView.Rows[i].Cells["SurplusItemDim"].Value;
                    if (SurplusItemDimValue != null)
                        if (double.TryParse(SurplusItemDimValue.ToString(), out double result))
                            LSItem.ItemDim = double.Parse(SurplusItemDimValue.ToString());

                    var SurplusItemLengthValue = SurplusItemDataGridView.Rows[i].Cells["SurplusItemLength"].Value;
                    if (SurplusItemLengthValue != null)
                        if (double.TryParse(SurplusItemLengthValue.ToString(), out double result))
                            LSItem.ItemL = double.Parse(SurplusItemLengthValue.ToString());

                    var SurplusItemNumValue = SurplusItemDataGridView.Rows[i].Cells["SurplusItemNum"].Value;
                    if (SurplusItemNumValue != null)
                        if (int.TryParse(SurplusItemNumValue.ToString(), out int result))
                            LSItem.ItemNum = int.Parse(SurplusItemNumValue.ToString());

                    var RemarkValue = SurplusItemDataGridView.Rows[i].Cells["SurplusItemRemark"].Value;
                    if (RemarkValue != null)
                        LSItem.UIRemark = RemarkValue.ToString();
                    tempLList.Add(LSItem);
                }
                ShareItemData.UISurplusItemList = tempLList;
            }
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                AutoModeUpload(false);
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                ManualModeUpload(false);
        }

        public string GetUploadUser()
        {
            string UploadUser = ULForm.UserNameText.Texts;
            return UploadUser = UploadUser != "" ? UploadUser : "";
        }

        //自动模式 上传
        private void AutoModeUpload(Boolean tempSaveF)
        {
            string UploadUser = GetUploadUser();
            //Collection UI Update Info 
            try
            {
                ATypeCollectionRCItemUIData();
                ATypeCollectionLabourItemUIData();
            }
            catch (Exception)
            {
                MessageBox.Show("收集数据阶段异常 请联系开发人员!");
            }
            //Check Board Num
            Boolean CheckBoardNumF = ATypeCheckBoardNum();
            if (!CheckBoardNumF)
                MessageBox.Show("板数量至少为1 请更改!");
            //Check RItem Num
            Boolean CheckItemNumF = ATypeCheckRItemNum();
            if(!CheckItemNumF)
                MessageBox.Show("零件数量至少为1 请更改!");
            Boolean CheckNRItemNumF = ATypeCheckNRItemNum();
            if (!CheckNRItemNumF)
                MessageBox.Show("零件数量至少为1 请更改!");
            //Check Rule
            Boolean CheckFangtieNumF = ATypeCheckFangtieNum();
            if(!CheckFangtieNumF)
                MessageBox.Show("方铁数量至少为2 请更改!");
            Boolean CheckHF = CheckInterceptHaningRule();
            if(CheckHF)
                MessageBox.Show("符合进柔性线 但吊令无数据 请输入吊令!");
           
            Boolean canUploadF = CheckBoardNumF && CheckItemNumF && CheckNRItemNumF && CheckFangtieNumF && !CheckHF;
            if (canUploadF)
            {
                Boolean pullingF = CheckMoldPullingLogic();
                if(pullingF)
                    httpUtils.ATypeSendERPDataEvent(UploadUser, tempSaveF);
            }
        }

        //校验整套模吊令
        public Boolean CheckMoldPullingLogic()
        {
            Boolean pullingF = CU.CheckMoldPullingParamBeforeUpload();
            if (!pullingF)
                pullingWindow.ShowDialog();
            return pullingF;
        }

        public Boolean ATypeCheckBoardNum()
        {
            Boolean Res = true;
            List<BoardSectionItem> BList = AssemblyShareData.AUIBlueSectionList;
            int allBNum = BList.Count();
            if(allBNum != 0)
            {
                BList.ForEach(item =>
                {
                    Boolean F = item.Num >= 1;
                    if (!F)
                        Res = false;
                });
            }
            return Res;
        }

        public Boolean ATypeCheckRItemNum()
        {
            Boolean Res = true;
            List<SingleItem> ItemList = ShareItemData.UIItemList;
            int allBNum = ItemList.Count();
            if (allBNum != 0)
            {
                ItemList.ForEach(item =>
                {
                    Boolean F = item.ItemNum >= 1;
                    if (!F)
                        Res = false;
                });
            }
            return Res;
        }

        public Boolean ATypeCheckNRItemNum()
        {
            Boolean Res = true;
            List<LabourSingleItem> ItemList = ShareItemData.UISurplusItemList;
            int allBNum = ItemList.Count();
            if (allBNum != 0)
            {
                ItemList.ForEach(item =>
                {
                    Boolean F = item.ItemNum >= 1;
                    if (!F)
                        Res = false;
                });
            }
            return Res;
        }

        public Boolean ATypeCheckFangtieNum()
        {
            Boolean Res = false;
            //方铁
            List<BoardSectionItem> FBList = AssemblyShareData.AUIBlueSectionList.FindAll(item => item.BoardCode.Equals("fangtie"));
            if (FBList.Count > 0)
            {
                List<int> FNumList = FBList.Select(item => item.Num).ToList();
                int allNum = FNumList.Sum();
                Res = allNum > 1;
            }
            else
                Res = true;
            return Res;
        }

        //吊令兜底校验
        private Boolean CheckInterceptHaningRule()
        {
            Boolean Res = false;
            Boolean NoFillHangDataF = IsATypeHanginUINotData();
            if (NoFillHangDataF)
                Res = IsHaningIntoFW();
            return Res;
        }

        private Boolean IsATypeHanginUINotData()
        {
            int allHas = 0;
            int BRowNum = BoardDataGridView.Rows.Count;
            for(int i = 0; i < BRowNum; i++)
            {
                var V = BoardDataGridView.Rows[i].Cells["HangingHole"].Value;
                if (V != null)
                {
                    string Value = V.ToString();
                    Boolean F = Value.Equals("标准") || Value.Equals("非标");
                    if(F)
                        allHas++;
                }
            }
            if (allHas == 0)
                return true;
            return false;
        }

        //吊令进柔性线判定
        private Boolean IsHaningIntoFW()
        {
            string targetMS = null;
            Boolean Res = false;
            string NowMoldSize = ComputedUtils.ATypeGetMoldSizeFormat();
            string AStr = null;
            string BStr = null;
            string Fancy = (string)RecognizeUtils.dataForm.FancySelectBox.SelectedItem;
            int aIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("aBoard"));
            if(aIndex != -1)
            {
                string tempAT = AssemblyShareData.ASectionList[aIndex].PlateThick.ToString();
                if (tempAT.Length < 3)
                    AStr = tempAT.PadLeft(3, '0');
                else
                    AStr = tempAT;
            }
            int bIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardCode.Equals("bBoard"));
            if (bIndex != -1)
            {
                string tempBT = AssemblyShareData.ASectionList[bIndex].PlateThick.ToString();
                if (tempBT.Length < 3)
                    BStr = tempBT.PadLeft(3, '0');
                else
                    BStr = tempBT;
            }
            if(AStr != null && BStr != null)
                targetMS = "M" + NowMoldSize + Fancy + AStr + BStr;
            if (targetMS != null)
                Res = CU.IsFlexibleWireHaing(targetMS);
            return Res;
        }

        //手动模式 整理上送ERP加工数据
        private ProcessData MTypeTidyUpERPProcessData()
        {
            ProcessData ResData = new ProcessData();
            string JobNumber = (string)RecognizeUtils.dataForm.ULForm.UserAccountText.Texts;
            string Fancy = (string)RecognizeUtils.dataForm.FancySelectBox.SelectedItem;
            string ModeNum = RecognizeUtils.dataForm.ModeNumText.Texts;
            var uploadtime = DateTime.Now;
            string tempOrder = "R2D" + uploadtime.ToString("yymmddHHmmss") + "M";
            //Basic Info
            string MouldStr = this.MoldSizeBox.Text;
            Boolean moldSizeF = int.TryParse(MouldStr, out int moldSize);
            if (moldSizeF)
            {
                //Collection Data
                ModeBasicData BasicData = new ModeBasicData();
                BasicData.Customer = RecognizeUtils.CustomerNum;
                BasicData.FancyType = Fancy;
                BasicData.ModeNum = ModeNum;
                BasicData.ModeSize = moldSize.ToString();
                BasicData.BatchNum = (string)RecognizeUtils.dataForm.BatchNumBox.Texts;
                BasicData.JobNumber = JobNumber;
                BasicData.tempOrderNumber = tempOrder;
                ResData.BasicData = BasicData;
                //Board
                List<ManualBoardItem> MBoardList = AssemblyShareData.MSectionList;
                List<ProcessBoard> tempProcessBoard = new List<ProcessBoard>();
                //Need Upload Frame 
                List<FrameItem> FrameList = new List<FrameItem>();

                for (int i = 0; i < MBoardList.Count; i++)
                {
                    ProcessBoard tempItem = new ProcessBoard();
                    tempItem.BoardCode = MBoardList[i].BoardCode;
                    tempItem.Plate_Name = MBoardList[i].BoardName;
                    tempItem.BoardUID = MBoardList[i].BoardUID;
                    tempItem.Width = MBoardList[i].PlateWidth;
                    tempItem.Length = MBoardList[i].PlateLength;
                    tempItem.Thickness = MBoardList[i].PlateThick;
                    tempItem.Steel_Desc = MBoardList[i].Steel.SteelName;
                    tempItem.Steel_Code = MBoardList[i].Steel.SteelCode;
                    tempItem.LaringDim = MBoardList[i].Hanging.HangingParam.Dim;
                    tempItem.LaringNum = MBoardList[i].Hanging.Num;
                    tempItem.Remark = MBoardList[i].UIRemark;
                    if (MBoardList[i].Hanging.standardType == StandardType.Standard)
                        tempItem.Standard_Laring = true;
                    if (MBoardList[i].Hanging.standardType == StandardType.NonStandard)
                        tempItem.Standard_Laring = false;
                    tempItem.Qty = MBoardList[i].Num;
                    //Hole Distance Standard 
                    if (MBoardList[i].PitchHoleStandard == StandardType.Standard)
                        tempItem.Standard_Plate = true;
                    if (MBoardList[i].PitchHoleStandard == StandardType.NonStandard)
                        tempItem.Standard_Plate = false;
                    tempProcessBoard.Add(tempItem);
                    if (MBoardList[i].frameItem.BoardUID != null)
                        FrameList.Add(MBoardList[i].frameItem);
                }
                ResData.FrameData = FrameList;
                ResData.BoardData = tempProcessBoard;
                //Item
                List<ManualItem> MItemList = ShareItemData.MItemList;
                List<ItemBaseParamData> tempProcessItem = new List<ItemBaseParamData>();
                for (int i = 0; i < MItemList.Count; i++)
                {
                    if(MItemList[i].ItemUID != null)
                    {
                        ItemBaseParamData tempItem = new ItemBaseParamData();
                        tempItem.ItemType = (int)MItemList[i].ItemNameType;
                        tempItem.ItemName = MItemList[i].ItemName;
                        tempItem.Dim = MItemList[i].Dim;
                        tempItem.Length = MItemList[i].L;
                        tempItem.Num = MItemList[i].Num;
                        tempProcessItem.Add(tempItem);
                    }
                }
                //Merge Same Spe Item 
                tempProcessItem = MTypeMergeSameSepItem(tempProcessItem);
                ResData.ItemData = tempProcessItem;
                //Extra Info
                ResData.ExtrajudgeInfo.gpRevFlag = MGPInverBox.Checked;
                ResData.ExtrajudgeInfo.rpOverSpFlag = MRPOverstBoardBox.Checked;
                ResData.ExtrajudgeInfo.gpOverSpFlag = MGPOverspBoardBox.Checked;
            }
            return ResData;
        }

        //MType Merge Need Same Spe Upload Item
        private List<ItemBaseParamData> MTypeMergeSameSepItem(List<ItemBaseParamData> PrItemList)
        {
            List<ItemBaseParamData> ResList = new List<ItemBaseParamData>();
            if (PrItemList.Count > 0)
            {
                Dictionary<int, List<ItemBaseParamData>> Dic = new Dictionary<int, List<ItemBaseParamData>>();
                for (int i = 0; i < PrItemList.Count; i++)
                {
                    if (Dic.ContainsKey(PrItemList[i].ItemType))
                    {
                        ItemBaseParamData DicItem = Dic[PrItemList[i].ItemType].First();
                        if (JudgeItemSameSpecification(DicItem, PrItemList[i]))
                        {
                            int ToAddNum = PrItemList[i].Num;
                            Dic[PrItemList[i].ItemType].First().Num += ToAddNum;
                        }
                        else
                            Dic[PrItemList[i].ItemType].Add(PrItemList[i]);
                    }
                    else
                        Dic.Add(PrItemList[i].ItemType, new List<ItemBaseParamData>() { PrItemList[i] });
                }
                List<int> DicKeys = Dic.Keys.ToList();
                if (DicKeys.Count > 0)
                    DicKeys.ForEach(key => ResList.AddRange(Dic[key]));
            }
            if (ResList.Count > 0)
            {
                ResList = ResList.OrderBy(item => item.SortNo).ToList();
                for (int i = 0; i < ResList.Count; i++)
                    ResList[i].SortNo = i + 1;
            }
            return ResList;
        }

        //动态查询暂存的中途记录
        public static void SearchDBTempRecordInfo()
        {
            string nowSysJobNumberName = (string)RecognizeUtils.dataForm.ULForm.UserNameText.Texts;
            nowSysJobNumberName = nowSysJobNumberName.Trim();
            string tagType = "UploadRecordList";
            ParamsConfigData.userTempRecordList = new List<AMTypeUPloadRecordInfo>();
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string connectionStr = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            using (SqlConnection connection = new SqlConnection(connectionStr))
            {
                try
                {
                    string sqlQuery = "SELECT * FROM [DXMG].[dbo].[R2D_UploadRecord] WHERE jobNumberName = @nowSysJobNumberName AND (uploadType = 3 OR uploadType = 4) ORDER BY uploadTime DESC";
                    using (SqlCommand command = new SqlCommand(sqlQuery, connection))
                    {
                        command.Parameters.Add("@nowSysJobNumberName", SqlDbType.NVarChar).Value = nowSysJobNumberName;
                        using (SqlDataAdapter Adapter = new SqlDataAdapter(command))
                        {
                            Adapter.TableMappings.Add("Table", tagType);
                            DataSet DispostionData = new DataSet();
                            Adapter.Fill(DispostionData);
                            
                            ParamsConfigData.userTempRecordList = Mould.InitRecordDisposition(DispostionData, tagType);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        //Del DB Temp Record
        public static void DelDBTempRecordInfo(string TempUID)
        {
            string nowSysJobNumberName = (string)RecognizeUtils.dataForm.ULForm.UserNameText.Texts;
            nowSysJobNumberName = nowSysJobNumberName.Trim();
            ParamsConfigData.userTempRecordList = new List<AMTypeUPloadRecordInfo>();
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string connectionStr = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            using (SqlConnection connection = new SqlConnection(connectionStr))
            {
                try
                {
                    string delSQL = "DELETE FROM [DXMG].[dbo].[R2D_UploadRecord] WHERE jobNumberName = @nowSysJobNumberName AND uploadType = 3 AND UID = @TempUID";
                    using (SqlCommand command = new SqlCommand(delSQL, connection))
                    {
                        command.Parameters.Add("@nowSysJobNumberName", SqlDbType.NVarChar).Value = nowSysJobNumberName;
                        command.Parameters.Add("@TempUID", SqlDbType.NVarChar).Value = TempUID;
                        connection.Open();
                        int rowsAffected = command.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
        }

        //动态查询上传记录
        public static void SearchDBUploadRecordInfo()
        {
            string nowSysJobNumberName = (string)RecognizeUtils.dataForm.ULForm.UserNameText.Texts;
            nowSysJobNumberName = nowSysJobNumberName.Trim();
            string tagType = "UploadRecordList";
            ParamsConfigData.userAMUploadRIList = new List<AMTypeUPloadRecordInfo>();
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string connectionStr = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            using (SqlConnection connection = new SqlConnection(connectionStr))
            {
                try
                {
                    string sqlQuery = "SELECT top(100) * FROM [DXMG].[dbo].[R2D_UploadRecord] WHERE jobNumberName = @nowSysJobNumberName AND uploadType != 3 ORDER BY uploadTime DESC";
                    using (SqlCommand command = new SqlCommand(sqlQuery, connection))
                    {
                        command.Parameters.Add("@nowSysJobNumberName", SqlDbType.NVarChar).Value = nowSysJobNumberName;
                        using (SqlDataAdapter Adapter = new SqlDataAdapter(command))
                        {
                            Adapter.TableMappings.Add("Table", tagType);
                            DataSet DispostionData = new DataSet();
                            Adapter.Fill(DispostionData);
                            ParamsConfigData.userAMUploadRIList = Mould.InitRecordDisposition(DispostionData, tagType);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

        }

        //手动模式 上传前 校验数据 TO DO
        private AMTypeCheckWarn MTypeCheckBeforeUpload()
        {
            AMTypeCheckWarn Res = new AMTypeCheckWarn();
            StringBuilder strBuilder = new StringBuilder();
            List<ManualBoardItem> boardList = AssemblyShareData.MSectionList;
            for(int i = 0; i < boardList.Count; i++)
            {
                if (boardList[i].PlateThick == 0)
                {
                    string tempStr = boardList[i].BoardName + "板厚不能为0";
                    strBuilder.AppendLine(tempStr);
                    Res.warnF = false;
                }
            }
            Res.tig = strBuilder.ToString();
            return Res;
        }

        //手动模式 加工孔 TO DO
        private List<HoleMould> MTypeTransToProcessHoleData(List<ManualBoardItem> BoardList)
        {
            // 孔加工数据
            List<HoleMould> ResPHoleList = new List<HoleMould>();
            BoardList = BoardList.OrderBy(item => item.MBSortNum).ToList();
            for (int i = 0; i < BoardList.Count; i++)
            {
                HoleMould HItem1 = new HoleMould();
                HItem1.plate_name = BoardList[i].BoardName;
                HItem1.BoardCode = BoardList[i].BoardCode;
                HItem1.BoardUID = BoardList[i].BoardUID;
                HItem1.L = Convert.ToDecimal(BoardList[i].PlateLength);
                HItem1.W = Convert.ToDecimal(BoardList[i].PlateWidth);
                HItem1.H = Convert.ToDecimal(BoardList[i].PlateThick);
                HItem1.Bat = BoardList[i].Steel.SteelName;
                HItem1.Plate_Sur = "正面";
                HItem1.plate_Z0 = BoardList[i].PArg.plateZ0;
                //HItem1.plate_LineNo = BoardList[i].plateLineNo;
                ResPHoleList.Add(HItem1);
                HoleMould HItem2 = new HoleMould();
                HItem2.plate_name = BoardList[i].BoardName;
                HItem2.BoardCode = BoardList[i].BoardCode;
                HItem2.BoardUID = BoardList[i].BoardUID;
                HItem2.L = Convert.ToDecimal(BoardList[i].PlateLength);
                HItem2.W = Convert.ToDecimal(BoardList[i].PlateWidth);
                HItem2.H = Convert.ToDecimal(BoardList[i].PlateThick);
                HItem2.Bat = BoardList[i].Steel.SteelName;
                HItem2.Plate_Sur = "反面";
                //HItem2.plate_LineNo = BoardList[i].plateLineNo;
                HItem2.plate_Z0 = BoardList[i].PArg.plateZ0;
                ResPHoleList.Add(HItem2);
            }

            List<ManualItem> MItemList = ShareItemData.MItemList;
            for(int i = 0; i < MItemList.Count; i++)
            {
                string ItemCode = MItemList[i].ItemCode;
                if (ItemCode.Equals("SpaceBlockScrew"))
                {
                    string TDBUID = MItemList[i].holeArg.PBArgInfo.TDBoardUID;
                    List<string> BUIDList = MItemList[i].BoardUIDList;
                    if(BUIDList.Count > 0)
                    {
                        for(int j = 0; j < BUIDList.Count; j++)
                        {
                            Boolean bpF = BUIDList[j].Contains("bpBoard");
                            if (bpF)
                            {
                                int MBIndex = ResPHoleList.FindIndex(item => item.BoardCode.Equals("bpBoard") && item.Plate_Sur.Equals("反面"));
                                if(MBIndex != -1)
                                {
                                    //托位沉头孔
                                    decimal TD = MItemList[i].holeArg.TD;
                                    HoleData HDItem = ConvertUtils.MTypeBuildScrewHoleByItem(MItemList[i], HoleProcessType.Sinkhead);
                                    HDItem.HPointList.AddRange(MItemList[i].TempHPointList);
                                    for(int k = 0; k < HDItem.HPointList.Count; k++)
                                        HDItem.HPointList[k].Z1 = TD;
                                    ResPHoleList[MBIndex].HoleDataList.Add(HDItem);
                                }
                            }
                            else
                            {
                                //盲牙孔
                                if (j == BUIDList.Count - 1)
                                {
                                    int MBIndex = ResPHoleList.FindIndex(item => item.BoardCode.Equals("bpBoard") && item.Plate_Sur.Equals("反面"));
                                    decimal toochH = 5;
                                    if (MItemList[i].Dim > 20)
                                        toochH = 10;
                                    HoleData HDItem = ConvertUtils.MTypeBuildScrewHoleByItem(MItemList[i], HoleProcessType.BlindScrew);
                                    HDItem.HPointList.AddRange(MItemList[i].TempHPointList);
                                    for (int k = 0; k < HDItem.HPointList.Count; k++)
                                        HDItem.HPointList[k].Z1 = toochH;
                                }
                                //通孔
                                else
                                {
                                    Boolean fangtieF = BUIDList[j].Contains("fangtie");
                                    if (fangtieF)
                                    {
                                        ManualBoardItem targetFB = BoardList.Find(item => item.BoardUID.Equals(BUIDList[j]));
                                        if(targetFB != null)
                                        {
                                            List<HoleMould> fangtieMouldList = ResPHoleList.FindAll(item => item.BoardCode.Equals("fangtie")
                                            && item.Plate_Sur.Equals("反面"));
                                            for(int k = 0; k < fangtieMouldList.Count; k++)
                                            {
                                                HoleData HDItem = MTypeBuildScrewHoleByItem(MItemList[i], HoleProcessType.ThroughScrew);
                                                int FMouldIndex = ResPHoleList.FindIndex(item => item.BoardUID.Equals(fangtieMouldList[k].BoardUID));
                                                if(FMouldIndex != -1)
                                                {
                                                    List<HPoint2D> tempItemHPointList = MItemList[i].TempHPointList;
                                                    for(int l = 0; l < tempItemHPointList.Count; l++)
                                                    {
                                                        HPoint2D HPItem = new HPoint2D();
                                                        HPItem.HoleName = tempItemHPointList[l].HoleName;
                                                        HPItem.X = targetFB.PArg.plateX0 - tempItemHPointList[l].X;
                                                        HPItem.X = Math.Round(HPItem.X, 0);
                                                        HPItem.Y = tempItemHPointList[l].Y;
                                                        HPItem.Y = Math.Round(HPItem.Y, 0);
                                                        HPItem.Z0 = 0;
                                                        HPItem.Z1 = Convert.ToDecimal(targetFB.PArg.plateZ0);
                                                        HDItem.HPointList.Add(HPItem);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            
            return ResPHoleList;
        }

        //手动模式 上传
        private void ManualModeUpload(Boolean tempSaveF)
        {
            //List<ManualBoardItem>  tempArgBList = ConvertUtils.MtypePathBArg();
            //ConvertUtils.MTypePatchItemArg();
            //ConvertUtils.MTypeSplitCoor();
            //MTypeTransToProcessHoleData(tempArgBList);
            Boolean checkF = HttpUtils.CheckInfoBeforeUploadRule(tempSaveF);
            if (checkF)
            {
                string UploadUser = GetUploadUser();
                MTypeAllCheckBoxVInfo BVInfo = new MTypeAllCheckBoxVInfo();
                BVInfo.MGPInverF =  MGPInverBox.Checked;
                BVInfo.MGPOverspBoardF = MGPOverspBoardBox.Checked;
                BVInfo.MRPOverstBoardF = MRPOverstBoardBox.Checked;
                BVInfo.MfangtieLockspBoardF = MfangtieLockspBoardBox.Checked;
                BVInfo.MRPAddTeethF = MRPAddTeethBox.Checked;
                BVInfo.MRPScrewF = MRPScrewBox.Checked;
                BVInfo.MEGPF = MEGPCheckBox.Checked;
                ProcessData PostData = MTypeTidyUpERPProcessData();
                httpUtils.SendDataToDbAndERP(BVInfo,PostData, tempSaveF);
            }
        }

        //清空按钮
        private void ClearBtn_Click(object sender, EventArgs e)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                ClearAutoPageData();
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                ClearManualPageData();
        }

        //清除 自动模式所有相关数据
        private void ClearAutoPageData()
        {
            ClearAllAutoPageUI();
            RecognizeUtils.ClearAVData();
            List<StandardCategoryBoard> FancyPlateList = ParamsConfigData.FancyPlateList;
            List<StandardCategoryBoard> tempList =
                FancyPlateList.FindAll(item => item.category.Equals(OldFancySelectItem))
                .OrderBy(item => item.sortNum).ToList();
            AutoPageResetBoardDataByCategory(tempList);
            StandardShareScopeItemParam.ClearStandardScopeData();
        }

        //清除 手动模式所有相关数据
        private void ClearManualPageData()
        {
            MTypeABoardBox.Value = 0;
            MTypeBBoardBox.Value = 0;
            MTypeCBoardBox.Value = 0;
            InitAndReSetManualData("RESET");
        }
  
        //清除加工项目window数据&UI
        public void AutoPageClearProcessData()
        {
            AssemblyShareData.egpProcessinfo = new EGPProcessinfo();
            egpWindow.ResetUI();
            AssemblyShareData.koHoleProcessinfo = new KOHoleProcessInfo();
            koHoleWindow.ResetUI();
            AssemblyShareData.sHoleProcessInfo = new SHoleProcessInfo();
            springHoleWindow.ResetUI();
        }

        //自动界面 清除
        public void ClearAllAutoPageUI()
        {
            AutoPageClearProcessData();
            ModeNumText.Texts = null;
            BatchNumBox.Texts = null;
            if (BoardDataGridView.Rows.Count > 0)
                BoardDataGridView.Rows.Clear();
            if (ItemDataGridView.Rows.Count > 0)
                ItemDataGridView.Rows.Clear();
            if (SurplusItemDataGridView.Rows.Count > 0)
                SurplusItemDataGridView.Rows.Clear();
        }

        private void ModeNumBtn_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            Commad.GetCADModeNum();
        }

        //用户搜索
        private void CustomerUpdate(object sender, EventArgs e)
        {
            string CustomerSearchText = CustomerSelect.Text;
            List<VCustomer> OriginList = ParamsConfigData.CustomerList;
            List<VCustomer> TargetList = new List<VCustomer>();
            for (int i = 0; i < OriginList.Count; i++)
            {
                Boolean F = OriginList[i].showContent.Contains(CustomerSearchText);
                if (F)
                    TargetList.Add(OriginList[i]);
            }
            if (CustomerSelect.Items.Count > 0)
                CustomerSelect.Items.Clear();
            CustomerSelect.Items.AddRange(TargetList.ToArray());
            CustomerSelect.DisplayMember = "showContent";
            CustomerSelect.ValueMember = "customerNumber";
            CustomerSelect.DroppedDown = true;
            Cursor = Cursors.Default;
            CustomerSelect.Text = CustomerSearchText;
            CustomerSelect.SelectedValue = null;
            CustomerSelect.Select(CustomerSelect.Text.Length, 0);
        }

        //花式搜索
        private void MoldSelectUpdate(object sender, EventArgs e)
        {
            System.Windows.Forms.ComboBox comboBox = (System.Windows.Forms.ComboBox)sender;
            int caretIndex = comboBox.SelectionStart;
            if(comboBox.Text != null)
             comboBox.Text = comboBox.Text.ToUpper();
            string SearchText = FancySelectBox.Text;
            List<StandardMoldType> OriginList = ParamsConfigData.MoldTypeList;
            List<StandardMoldType> TargetList = new List<StandardMoldType>();
            for (int i = 0; i < OriginList.Count; i++)
            {
                Boolean F = OriginList[i].category.Contains(SearchText);
                if (F)
                    TargetList.Add(OriginList[i]);
            }
            if (FancySelectBox.Items.Count > 0)
                FancySelectBox.Items.Clear();
            if(TargetList.Count > 0)
            {
                string[] strArray = TargetList.Select(item => item.category).ToArray();
                FancySelectBox.Items.AddRange(strArray);
                FancySelectBox.DroppedDown = true;
                Cursor = Cursors.Default;
                FancySelectBox.SelectionStart = caretIndex;
            }
        }

        private void CustomerBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            VCustomer beChoosedItem = (VCustomer)CustomerSelect.SelectedItem;
            if(beChoosedItem != null)
            {
                string CNum = beChoosedItem.customerNumber;
                CustomerSelect.SelectedValue = CNum;
                RecognizeUtils.CustomerNum = CNum;
            }
        }

        //点击用户设置
        private void userSetBtn_Click(object sender, EventArgs e)
        {
            ULForm.Show();
        }

        public void SurplusItemComboBoxChanged(object sender, EventArgs e)
        {
            System.Windows.Forms.ComboBox combox = sender as System.Windows.Forms.ComboBox;
            combox.Leave += new EventHandler(SurplusItemComboBoxLeave);
        }

        //抓侧面框两条横线 量出深度
        public void MeaSideFrameDepthByTwoTLine(int operFrameIndex)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            // 获取编辑器和选择集
            Editor editor = doc.Editor;
            List<BoardSectionItem> targetList = AssemblyShareData.AUIBlueSectionList;
            BoardSectionItem targetBoard = targetList[operFrameIndex];
            string boardName = targetBoard.BoardName;
            editor.WriteMessage("点选" + boardName + "侧视图框最高点&低点横线");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    List<double> pyList = new List<double>();
                    List<CAD_Line> lineList = new List<CAD_Line>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            // 获取块表和模型空间
                            BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is Line line)
                                    {
                                        CAD_Line Item = new CAD_Line();
                                        Item.StartPoint.X = line.StartPoint.X;
                                        Item.StartPoint.Y = line.StartPoint.Y;
                                        Item.EndPoint.X = line.EndPoint.X;
                                        Item.EndPoint.Y = line.EndPoint.Y;
                                        Item.Length = line.Length;
                                        lineList.Add(Item);
                                        pyList.Add(line.StartPoint.Y);
                                        pyList.Add(line.EndPoint.Y);
                                    }
                                }
                            }
                            if(pyList.Count > 0)
                            {
                                double MaxY = pyList.Max();
                                double MinY = pyList.Min();
                                targetBoard.frameItem.FrameDepth = MaxY - MinY;
                                //修改界面精框提示语
                                RecognizeUtils.SetFrameItemTig(operFrameIndex);
                                AutoPageRenderBoardUIData(RenderType.AfterRecoginzeFrame);
                            }
                            tr.Commit();
                            doc.Editor.Regen();
                        }
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                }
            }
        }

        //抓侧面框标注 两处深度
        public void MeaSideFrameDepthLabel(int operFrameIndex)
        {
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            // 获取编辑器和选择集
            Editor editor = doc.Editor;
            List<BoardSectionItem> targetList = AssemblyShareData.AUIBlueSectionList;
            BoardSectionItem targetBoard = targetList[operFrameIndex];
            string boardName = targetBoard.BoardName;
            editor.WriteMessage("点选" + boardName + "侧视图框深标注");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    double? dimValue = null;
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            // 获取块表和模型空间
                            BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is AlignedDimension dim)
                                    {
                                        double Y1 = dim.XLine1Point.Y;
                                        double Y2 = dim.XLine2Point.Y;
                                        dimValue = Math.Abs(Y1 - Y2);
                                    }
                                }
                            }
                            if (dimValue != null)
                            {
                                targetBoard.frameItem.FrameDepth = (double)dimValue;
                                //修改界面精框提示语
                                RecognizeUtils.SetFrameItemTig(operFrameIndex);
                                AutoPageRenderBoardUIData(RenderType.AfterRecoginzeFrame);
                            }
                            tr.Commit();
                            doc.Editor.Regen();
                        }
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                }
            }
            else
            {

            }
        }

        //精框测量侧视图 修改界面数据 事件
        public void FramSideLabelEvent(int operIndex,string strategy)
        {
            this.Hide();
            if (strategy.Equals("TWOT"))
                MeaSideFrameDepthByTwoTLine(operIndex);
            if (strategy.Equals("LABEL"))
                MeaSideFrameDepthLabel(operIndex);
            if (this.WindowState == FormWindowState.Minimized)
                this.WindowState = FormWindowState.Normal;
            this.Show();
        }

        //弹簧孔 组装图 抓数
        public SHoleProcessInfo SHoleAssemFunc()
        {
            SHoleProcessInfo Res = new SHoleProcessInfo();
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            editor.WriteMessage("点选组装图弹簧孔直线特征线段");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    List<double> pxList = new List<double>();
                    List<double> pyList = new List<double>();
                    List<MixedCAD_Line> lineList = new List<MixedCAD_Line>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction transaction = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = transaction.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    if (entity is Line line)
                                    {
                                        MixedCAD_Line Item = new MixedCAD_Line();
                                        Item.StartPoint.CustomerPoint.X = line.StartPoint.X;
                                        Item.StartPoint.CustomerPoint.Y = line.StartPoint.Y;
                                        Item.EndPoint.CustomerPoint.X = line.EndPoint.X;
                                        Item.EndPoint.CustomerPoint.Y = line.EndPoint.Y;
                                        Item.Length = line.Length;
                                        Item = RecognizeUtils.TransCADItemLineData(Item);
                                        lineList.Add(Item);
                                    }
                                }
                            }
                        }
                        List<MixedCAD_Line> VList = lineList.FindAll(item => item.LineType == CADLineType.YDirLine).ToList();
                        if (VList.Count > 0)
                        {
                            pxList.AddRange(VList.Select(item => item.StartPoint.CustomerPoint.X));
                            pxList.AddRange(VList.Select(item => item.EndPoint.CustomerPoint.X));
                            pyList.AddRange(VList.Select(item => item.StartPoint.CustomerPoint.Y));
                            pyList.AddRange(VList.Select(item => item.EndPoint.CustomerPoint.Y));
                            double minX = pxList.Min();
                            double maxX = pxList.Max();
                            double minY = pyList.Min();
                            double maxY = pyList.Max();
                            double sDim = Math.Abs(maxX - minX);
                            double sDepth = Math.Abs(maxY - minY);
                            Res.depth = sDepth;
                            Res.dim = sDim;
                        }
                        transaction.Commit();
                        doc.Editor.Regen();

                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                }
            }
            else
            {

            }
            return Res;
        }

        public void SetControlTempSelectIndexAction()
        {
            this.R2DControl.SelectedIndex = 2;
        }

        //弹簧孔 平面图 抓数
        public SHoleProcessInfo SProjectionFunc()
        {
            SHoleProcessInfo Res = new SHoleProcessInfo();
            //List<CAD_Point> ResPList = new List<CAD_Point>();
            //int cNum = 0;
            //Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            //Database db = doc.Database;
            //Editor editor = doc.Editor;
            //editor.WriteMessage("点选平面图弹簧孔");
            //PromptSelectionResult selectionResult = editor.GetSelection();
            //if (selectionResult.Status == PromptStatus.OK)
            //{
            //    DocumentLock m_DocumentLock = doc.LockDocument();
            //    try
            //    {
            //        List<CAD_Circle> circleList = new List<CAD_Circle>();
            //        ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
            //        using (Transaction tr = db.TransactionManager.StartTransaction())
            //        {
            //            if (objectIds.Length > 0)
            //            {
            //                BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
            //                BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
            //                foreach (ObjectId objectId in objectIds)
            //                {
            //                    Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
            //                    if (entity != null)
            //                    {
            //                        if (entity is Circle circle)
            //                        {
            //                            CAD_Circle temp = new CAD_Circle();
            //                            temp.CAD_ObjectId = objectId;
            //                            temp.CenterPoint.X = circle.Center.X;
            //                            temp.CenterPoint.Y = circle.Center.Y;
            //                            temp.Diameter = circle.Diameter;
            //                            circleList.Add(temp);
            //                        }
            //                    }
            //                }
            //                //用户只选了一个
            //                if (circleList.Count == 1)
            //                {
            //                    CAD_Circle refCircle = circleList[0];
            //                    List<CAD_Circle> ResList = new List<CAD_Circle>();
            //                    List<CAD_Circle> targList1 = TopViewShareData.TopViewCircleList;
            //                    if(targList1.Count > 0)
            //                    {
                                    
            //                        List<CAD_Circle> resList1 = targList1.FindAll(item => item.Diameter == refCircle.Diameter);
            //                        if (resList1.Count > 0)
            //                        {
            //                            cNum += resList1.Count;
            //                            ResList.AddRange(resList1);
            //                        }
            //                        if(cNum == 0 )
            //                        {
            //                            List<CAD_Circle> resList2 = targList1.FindAll(item => item.Diameter == refCircle.Diameter);
            //                            if (resList2.Count > 0)
            //                            {
            //                                cNum += resList2.Count;
            //                                ResList.AddRange(resList2);
            //                            }
            //                        }
            //                    }
            //                    if(ResList.Count > 0)
            //                        ResPList = ResList.Select(item => item.CenterPoint).ToList();
            //                }
            //                //用户多选
            //                if(circleList.Count > 1)
            //                    ResPList = circleList.Select(item => item.CenterPoint).ToList();
            //                tr.Commit();
            //                doc.Editor.Regen();
            //            }
            //        }
            //    }
            //    catch (ZwSoft.ZwCAD.Runtime.Exception e)
            //    {
            //        throw;
            //    }
            //    finally
            //    {
            //        if (m_DocumentLock != null)
            //            m_DocumentLock.Dispose();
            //    }
            //}
            //else
            //{

            //}
            //if (cNum > 0)
            //    Res.num = cNum;
            //if(ResPList.Count > 1)
            //{
            //    List<double> XList = ResPList.Select(item => item.X).ToList();
            //    List<double> YList = ResPList.Select(item => item.Y).ToList();
            //    double XMin = XList.Min();
            //    double XMax = XList.Max();
            //    double YMin = YList.Min();
            //    double YMax = YList.Max();
            //    Res.posL = YMax - YMin;
            //    Res.posW = XMax - XMin;
            //    Boolean allRPF = true;
            //    //判断是否在回针位置 TODO
            //    List<ScrewHole> rpHoleList  = HoleCandidateShareData.ReturnPinCList;
            //    if(rpHoleList.Count > 0)
            //    {
            //        ResPList.ForEach(item =>
            //        {
            //            Boolean F = rpHoleList.FindIndex(rp => rp.CenterPoint.X == item.X
            //            && rp.CenterPoint.Y == item.Y) == -1;
            //            if (F)
            //                allRPF = false;
            //        });
            //        Res.hasRPPos = allRPF;
            //    }
            //}
            return Res;
        }

        //KO孔 平面图 抓数
        public KOHoleProcessInfo KOHoleProjectionFunc()
        {
            KOHoleProcessInfo Res = new KOHoleProcessInfo();
            List<CAD_Point> ResPList = new List<CAD_Point>();
            int cNum = 0;
            Document doc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor editor = doc.Editor;
            editor.WriteMessage("点选平面图KO孔");
            PromptSelectionResult selectionResult = editor.GetSelection();
            if (selectionResult.Status == PromptStatus.OK)
            {
                DocumentLock m_DocumentLock = doc.LockDocument();
                try
                {
                    List<CAD_Circle> circleList = new List<CAD_Circle>();
                    List<CAD_Text> textList = new List<CAD_Text>();
                    ObjectId[] objectIds = selectionResult.Value.GetObjectIds();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        if (objectIds.Length > 0)
                        {
                            BlockTable blockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                            BlockTableRecord modelSpace = tr.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            foreach (ObjectId objectId in objectIds)
                            {
                                Entity entity = tr.GetObject(objectId, OpenMode.ForRead) as Entity;
                                if (entity != null)
                                {
                                    //文字
                                    if(entity is DBText text)
                                    {
                                        CAD_Text Item = new CAD_Text();
                                        Item.PositionPoint = new CAD_Point();
                                        double X = Math.Round(text.Position.X, 3);
                                        double Y = Math.Round(text.Position.Y, 3);
                                        double Z = Math.Round(text.Position.Z, 3);
                                        Item.Centent = text.TextString;
                                        textList.Add(Item);
                                    }
                                    if (entity is MText mtext)
                                    {
                                        string textContent = mtext.Text;
                                        double X = Math.Round(mtext.Location.X, 3);
                                        double Y = Math.Round(mtext.Location.Y, 3);
                                        double Z = Math.Round(mtext.Location.Z, 3);
                                        string[] MTextList = textContent.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                                        for (int i = 0; i < MTextList.Length; i++)
                                        {
                                            CAD_Text Item = new CAD_Text();
                                            Item.PositionPoint = new CAD_Point();
                                            Item.PositionPoint.X = X;
                                            Item.PositionPoint.Y = Y;
                                            Item.PositionPoint.Z = Z;
                                            Item.Centent = MTextList[i];
                                            textList.Add(Item);
                                        }
                                    }
                                    //圆
                                    if (entity is Circle circle)
                                    {
                                        CAD_Circle temp = new CAD_Circle();
                                        temp.CAD_ObjectId = objectId;
                                        temp.CenterPoint.X = circle.Center.X;
                                        temp.CenterPoint.Y = circle.Center.Y;
                                        temp.Diameter = circle.Diameter;
                                        circleList.Add(temp);
                                    }
                                    //块参照
                                    else if (entity is BlockReference)
                                    {
                                        BlockReference blockRef = entity as BlockReference;
                                        // 获取块参照的位置
                                        Point3d blkPos = blockRef.Position;
                                        BlockTableRecord BlockItem = tr.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead) 
                                            as BlockTableRecord;
                                        // 遍历块定义中的所有实体
                                        foreach (ObjectId BobjectId in BlockItem)
                                        {
                                            DBObject dbObj = tr.GetObject(BobjectId, OpenMode.ForRead);
                                            //块 圆
                                            if (dbObj is Circle)
                                            {
                                                Circle BICircle = dbObj as Circle;
                                                CAD_Circle Item = new CAD_Circle();
                                                Item.CenterPoint.X = BICircle.Center.X;
                                                Item.CenterPoint.Y = BICircle.Center.Y;
                                                Item.IsBlockEleFlag = true;
                                                Item.BlockRefPosition.X = blkPos.X;
                                                Item.BlockRefPosition.Y = blkPos.Y;
                                                Item.Diameter = BICircle.Diameter;
                                                circleList.Add(Item);
                                            }
                                            if (dbObj is DBText dbText)
                                            {
                                                CAD_Text Item = new CAD_Text();
                                                Item.CAD_ObjectId = BobjectId;
                                                Item.PositionPoint = new CAD_Point();
                                                Item.PositionPoint.X = blkPos.X;
                                                Item.PositionPoint.Y = blkPos.Y;
                                                double X = Math.Round(dbText.Position.X, 3);
                                                double Y = Math.Round(dbText.Position.Y, 3);
                                                double Z = Math.Round(dbText.Position.Z, 3);
                                                Item.IsBlockEleFlag = true;
                                                Item.BlockRefPosition.X = blkPos.X;
                                                Item.BlockRefPosition.Y = blkPos.Y;
                                                Item.Centent = dbText.TextString;
                                                textList.Add(Item);
                                            }
                                            if (dbObj is MText BIMtext)
                                            {
                                                CAD_Text Item = new CAD_Text();
                                                Item.CAD_ObjectId = BobjectId;
                                                Item.PositionPoint = new CAD_Point();
                                                double X = Math.Round(BIMtext.Location.X, 3);
                                                double Y = Math.Round(BIMtext.Location.Y, 3);
                                                double Z = Math.Round(BIMtext.Location.Z, 3);
                                                Item.PositionPoint.X = X;
                                                Item.PositionPoint.Y = Y;
                                                Item.IsBlockEleFlag = true;
                                                Item.BlockRefPosition.X = blkPos.X;
                                                Item.BlockRefPosition.Y = blkPos.Y;
                                                Item.Centent = BIMtext.Text;
                                                textList.Add(Item);
                                            }
                                        }
                                    }
                                }
                            }
                            if(textList.Count > 0)
                            {
                                List<string> contentList = textList.Select(item => item.Centent).ToList();
                                Boolean KOF = contentList.Contains("KO");
                                if (KOF)
                                {

                                    ////用户只选了一个
                                    //if (circleList.Count == 1)
                                    //{
                                    //    CAD_Circle refCircle = circleList[0];
                                    //    List<CAD_Circle> ResList = new List<CAD_Circle>();
                                    //    List<CAD_Circle> targList1 = TopViewShareData.TopViewCircleList;
                                    //    if (targList1.Count > 0)
                                    //    {
                                    //        List<CAD_Circle> resList1 = targList1.FindAll(item => item.Diameter == refCircle.Diameter);
                                    //        if (resList1.Count > 0)
                                    //        {
                                    //            cNum += resList1.Count;
                                    //            ResList.AddRange(resList1);
                                    //        }
                                    //        if (cNum == 0)
                                    //        {
                                    //            List<CAD_Circle> resList2 = targList1.FindAll(item => item.Diameter == refCircle.Diameter);
                                    //            if (resList2.Count > 0)
                                    //            {
                                    //                cNum += resList2.Count;
                                    //                ResList.AddRange(resList2);
                                    //            }
                                    //        }
                                    //    }
                                    //    if (ResList.Count > 0)
                                    //        ResPList = ResList.Select(item => item.CenterPoint).ToList();
                                    //}
                                    ////用户多选
                                    //if (circleList.Count > 1)
                                    //    ResPList = circleList.Select(item => item.CenterPoint).ToList();
                                }
                                
                            }
                            
                            tr.Commit();
                            doc.Editor.Regen();
                        }
                    }
                }
                catch (ZwSoft.ZwCAD.Runtime.Exception e)
                {
                    throw;
                }
                finally
                {
                    if (m_DocumentLock != null)
                        m_DocumentLock.Dispose();
                }
            }
            else
            {

            }
            if (cNum > 0)
                Res.num = cNum;
            if (ResPList.Count > 1)
            {
               
            }
            return Res;
        }

        public void SurplusItemComboBoxLeave(object sender, EventArgs e)
        {
            System.Windows.Forms.ComboBox combox = sender as System.Windows.Forms.ComboBox;
            //做完处理 需撤销
            combox.SelectedIndexChanged -= new EventHandler(SurplusItemComboBoxChanged);
        }

        //自动模式 一键补齐吊令逻辑
        private void AutoTypeCompletePatchHangLogic(string patchType = null)
        {
            List<BoardSectionItem> BoardList = AssemblyShareData.AUIBlueSectionList;
            int boardNum = BoardDataGridView.Rows.Count;
            if (boardNum > 0)
            {
                for (int i = 0; i < boardNum; i++)
                {
                    var BluePrintHHFlagValue = BoardDataGridView.Rows[i].Cells["BluePrintHHFlag"].Value;
                    Boolean BluePrintHHFlag = Boolean.Parse(BluePrintHHFlagValue.ToString());
                    if (!BluePrintHHFlag)
                    {
                        var BoardCodeValue = BoardDataGridView.Rows[i].Cells["BoardCode"].Value;
                        var PlateThickValue = BoardDataGridView.Rows[i].Cells["PlateThick"].Value;
                        if (BoardCodeValue != null && PlateThickValue != null)
                        {
                            string BoardCode = BoardCodeValue.ToString();
                            if (double.TryParse(PlateThickValue.ToString(), out double result))
                            {
                                double PlateThick = double.Parse(PlateThickValue.ToString());
                                double pullingValue = CU.AutoSetPulllingParam(BoardCode, PlateThick, patchType);
                                if (pullingValue != -1)
                                {
                                    string boardUID = BoardDataGridView.Rows[i].Cells["BoardUID"].Value.ToString();
                                    int bIndex = BoardList.FindIndex(item => item.BoardUID.Equals(boardUID));
                                    if(bIndex != -1){
                                        BoardList[bIndex].Hanging.HangingParam.Dim = pullingValue;
                                        BoardList[bIndex].Hanging.Num = 2;
                                        BoardList[bIndex].Hanging.DimStandardType = StandardType.Standard;
                                        BoardList[bIndex].Hanging.PosstandardType = StandardType.Standard;
                                        BoardList[bIndex].Hanging.standardType = StandardType.Standard;
                                    }
                                    BoardDataGridView.Rows[i].Cells["HangingDim"].Value = pullingValue;
                                    BoardDataGridView.Rows[i].Cells["HangingHole"].Value = "标准";
                                    BoardDataGridView.Rows[i].Cells["HangingNum"].Value = 2;
                                }
                                else
                                {
                                    string boardUID = BoardDataGridView.Rows[i].Cells["BoardUID"].Value.ToString();
                                    int bIndex = BoardList.FindIndex(item => item.BoardUID.Equals(boardUID));
                                    if (bIndex != -1)
                                    {
                                        BoardList[bIndex].Hanging.HangingParam.Dim = 0;
                                        BoardList[bIndex].Hanging.Num = 0;
                                        BoardList[bIndex].Hanging.DimStandardType = StandardType.Untried;
                                        BoardList[bIndex].Hanging.PosstandardType = StandardType.Untried;
                                        BoardList[bIndex].Hanging.standardType = StandardType.Untried;
                                    }
                                    BoardDataGridView.Rows[i].Cells["HangingDim"].Value = "";
                                    BoardDataGridView.Rows[i].Cells["HangingHole"].Value = "";
                                    BoardDataGridView.Rows[i].Cells["HangingNum"].Value = "";
                                }
                            }
                        }
                    }
                }

            }
        }

        //手动模式 一键补齐吊令逻辑
        private void MTypeCompletePatchHangingLogic(string patchType = null)
        {
            MTypeSetPullingLogic(patchType);
            ReRenderPullingUI();
        }

        //一键补齐整套吊令 
        private void CompletePatchHangingBtn_Click(object sender, EventArgs e)
        {
            string pathType = "ALL";
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                AutoTypeCompletePatchHangLogic(pathType);
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                MTypeCompletePatchHangingLogic(pathType);
        }

        //按标准 一键补齐吊令 
        private void standardPatchHangBtn_Click(object sender, EventArgs e)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                AutoTypeCompletePatchHangLogic();
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                MTypeCompletePatchHangingLogic();
            
        }

        //渲染中途记录数据的列表UI
        public void RenderTempSaveRecordUI()
        {
            List<AMTypeUPloadRecordInfo> msList = ParamsConfigData.userTempRecordList;
            TempRecordDataGridView.Rows.Clear();
            for(int i = 0; i < msList.Count; i++)
            {
                DataGridView ItemData = new DataGridView();
                int rowIndex = TempRecordDataGridView.Rows.Add(ItemData);
                TempRecordDataGridView.Rows[rowIndex].Cells["TempRecordUID"].Value = msList[i].UID;
                TempRecordDataGridView.Rows[rowIndex].Cells["dwgFileName"].Value = msList[i].dwgfileName;
                TempRecordDataGridView.Rows[rowIndex].Cells["MoldNum"].Value = msList[i].modeNum;
                TempRecordDataGridView.Rows[rowIndex].Cells["BatchNum"].Value = msList[i].batchNum;
                TempRecordDataGridView.Rows[rowIndex].Cells["SaveTempRecordTime"].Value = msList[i].uploadTime.ToString();
                string utype = null;
                if (msList[i].uploadType == 3)
                    utype = "自动";
                if (msList[i].uploadType == 4)
                    utype = "手动";
                TempRecordDataGridView.Rows[rowIndex].Cells["OperType"].Value = utype;
                TempRecordDataGridView.Rows[rowIndex].Cells["RecordShowOper"].Value = "继续报价";
            }
        }

        //渲染用户上传数据的列表UI
        public void RenderUploadRecordUI()
        {
            List<AMTypeUPloadRecordInfo> msList = ParamsConfigData.userAMUploadRIList;
            RFForm.RecordDataGridView.Rows.Clear();
            for (int i = 0; i < msList.Count; i++)
            {
                DataGridView ItemData = new DataGridView();
                int rowIndex = RFForm.RecordDataGridView.Rows.Add(ItemData);
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["RecordUID"].Value = msList[i].UID;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["MoldNum"].Value = msList[i].modeNum;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["UpdatePeople"].Value = msList[i].jobNumberName;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["BatchNum"].Value = msList[i].batchNum;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["dwgFileName"].Value = msList[i].dwgfileName;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["UploadRecordTime"].Value = msList[i].uploadTime.ToString();
                string utype = "手动";
                if (msList[i].uploadType != 2)
                    utype = "自动";
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["uploadType"].Value = utype;
                RFForm.RecordDataGridView.Rows[rowIndex].Cells["RecordShowOper"].Value = "查看";
            }
        }

        public void ATypeRecordAction(AMTypeUPloadRecordInfo RInfo)
        {
            //Conditional Part
            ATypeRecordResetConOper(RInfo);
            //Primary Data Part
            ATypeRecordResetPriDataOper(RInfo);
        }

        public void ATypeRecordAction(AMTypeUPloadRecordInfo RInfo,Boolean recordF = false)
        {
            //Conditional Part
            ATypeRecordResetConOper(RInfo);
            //Primary Data Part
            ATypeRecordResetPriDataOper(RInfo, recordF);
        }

        private void MTypeRecordAction(AMTypeUPloadRecordInfo RInfo)
        {
            //Clear And Set Part Conditional Part
            MTypeRecordResetConOper(RInfo);
            //Set Primary Data And Part Conditional Part
            MTypeRecordResetPriDataOper(RInfo);
        }

        public void MTypeRecordAction(AMTypeUPloadRecordInfo RInfo,Boolean recordF = false)
        {
            //Clear And Set Part Conditional Part
            MTypeRecordResetConOper(RInfo);
            //Set Primary Data And Part Conditional Part
            MTypeRecordResetPriDataOper(RInfo, recordF);
        }

        //自动模式 查看记录 重置条件栏操作
        public void ATypeRecordResetConOper(AMTypeUPloadRecordInfo RInfo)
        {
            //清除自动整个界面
            ClearAllAutoPageUI();

            int customerIndex = CustomerSelect.FindString(RInfo.customer.Trim());
            if (customerIndex != -1)
                CustomerSelect.SelectedIndex = customerIndex;

            List<StandardMoldType> fancyList = ParamsConfigData.MoldTypeList;
            string[] strArray = fancyList.Select(item => item.category).ToArray();
            FancySelectBox.Items.AddRange(strArray);

            int fancyIndex = FancySelectBox.FindString(RInfo.fancy.Trim());
            if (fancyIndex != -1)
                FancySelectBox.SelectedIndex = fancyIndex;

            BatchNumBox.Texts = RInfo.batchNum;
            ModeNumText.Texts = RInfo.modeNum;
            this.Show();
        }

        private void MTypeRecordResetConOper(AMTypeUPloadRecordInfo RInfo)
        {
            ClearMCheck();
            ClearMBoardDataAndUI();
            ClearMItemDataAndUI();

            //条件栏
            int customerIndex = CustomerSelect.FindString(RInfo.customer.Trim());
            if (customerIndex != -1)
                CustomerSelect.SelectedIndex = customerIndex;

            int fancyIndex = FancySelectBox.FindString(RInfo.fancy.Trim());
            if (fancyIndex != -1)
                FancySelectBox.SelectedIndex = fancyIndex;

            this.MoldSizeBox.Text = RInfo.modeSize;
            this.BatchNumBox.Text = RInfo.batchNum;
            this.ModeNumText.Text = RInfo.modeNum;

            MSYS = ComputedUtils.GetSYSBreCodeByFancy(RInfo.modeSize);
            CADCommonForm.MoldTypeStr = RInfo.moldType.Trim();
        }

        //第一次查询
        private void ShowRecordBtn_Click(object sender, EventArgs e)
        {
            SearchDBUploadRecordInfo();
            RenderUploadRecordUI();
            RFForm.NormalShow();
        }

        private void ErrorDrawBtn_Click(object sender, EventArgs e)
        {
            string targetFolder = @"\\192.168.8.248\quopdf\R2D\ErrorDraw\";
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = true;
            dialog.Title = "请选择识别有误图纸和说明截图!";
            dialog.Filter = "所有文件(*.*)|*.*";
            var uploadtime = DateTime.Now;
            string JobNumber = (string)RecognizeUtils.dataForm.ULForm.UserNameText.Texts;
            string tempFloder = targetFolder +  JobNumber + "日期" + uploadtime.ToString("yyMMDDHHmmss");
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string[] fns = dialog.FileNames;
                if(fns.Length > 0)
                {
                    if (!Directory.Exists(tempFloder))
                    {
                        Directory.CreateDirectory(tempFloder);
                        tempFloder += "\\";
                    }

                    List<string> fnsList =  fns.ToList();
                    for(int i = 0; i < fnsList.Count; i++)
                    {
                        string tocopyFile = fnsList[i];
                        List<string> alloneFN = tocopyFile.Split('\\').ToList();
                        string suffixFN = alloneFN[alloneFN.Count - 1];
                        string ftpDrawName = tempFloder + suffixFN;
                        File.Copy(tocopyFile,ftpDrawName, true);
                    }
                }
            }

        }

        private void gpRevCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            ShareItemBoardShipInfo.extraShipInfo.gpRevFlag = gpRevCheckBox.Checked;
        }

        private void gpOverSpCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            ShareItemBoardShipInfo.extraShipInfo.gpOverSpFlag = gpOverSpCheckBox.Checked;
        }

        private void rpOverSpCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            ShareItemBoardShipInfo.extraShipInfo.rpOverSpFlag = rpOverSpCheckBox.Checked;
        }

        private void KOHoleBtn_Click(object sender, EventArgs e)
        {
            koHoleWindow.SetUI();
        }

        private void SpringHoleBtn_Click(object sender, EventArgs e)
        {
            springHoleWindow.SetUI();
        }

        private void EGPBtn_Click(object sender, EventArgs e)
        {
            egpWindow.SetUI();
        }

        private void BoardDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string ViewOperName = BoardDataGridView.Columns[e.ColumnIndex].Name;
            Boolean OperFrameF = ViewOperName.Equals("OperFrame");
            Boolean FrameTigF = ViewOperName.Equals("FrameTig");
            Boolean SteelF = ViewOperName.Equals("Steel");
            if (OperFrameF)
            {
                this.WindowState = FormWindowState.Minimized;
                RecognizeUtils.RecognizeBoardTopViewFrame(e.RowIndex);
            }
            if (FrameTigF)
                frameWindow.InitFrameWindow(e.RowIndex);
            if (SteelF)
                steelWindow.SetOriginOption(e.RowIndex);
            Boolean F = e.ColumnIndex == 3 || e.ColumnIndex == 6 || e.ColumnIndex == 7 || e.ColumnIndex == 8 || e.ColumnIndex == 11 || e.ColumnIndex == 14;
            if(F)
                BoardDataGridView.BeginEdit(true);
        }

        private bool CheckPullingAsUsualRule()
        {
            bool Res = false;
            int boardNum = BoardDataGridView.Rows.Count;
            if (boardNum > 0)
            {
                for (int i = 0; i < boardNum; i++) 
                {
                    var THangingDimV = BoardDataGridView.Rows[i].Cells["HangingDim"].Value;
                    var HangingNumV = BoardDataGridView.Rows[i].Cells["HangingNum"].Value;
                    var HangingHoleV = BoardDataGridView.Rows[i].Cells["HangingHole"].Value;
                    bool F1 = THangingDimV != null;
                    bool F2 = HangingNumV != null;
                    bool F3 = !HangingHoleV.ToString().Equals("");
                    if (F1 && F2 && F3)
                    {
                        Res = true;
                        return Res;
                    }
                }
            }
            return Res;
        }

        //吊令窗口回调
        private void PullingActionEvent(PullingPushType pullingType)
        {
            bool F1 = pullingType == PullingPushType.AsUsual;
            if(F1)
            {
                bool checkF = CheckPullingAsUsualRule();
                if(checkF)
                {
                    string UploadUser = GetUploadUser();
                    httpUtils.ATypeSendERPDataEvent(UploadUser, false);
                }
                else
                    MessageBox.Show("至少需要一条配板吊令数据才能照常上传!");

            }
            bool F2 = pullingType == PullingPushType.StandardSup;
            if (F2)
            {
                AutoTypeCompletePatchHangLogic();
                string UploadUser = GetUploadUser();
                httpUtils.ATypeSendERPDataEvent(UploadUser, false);
            }
            bool F3 = pullingType == PullingPushType.wholeRep;
            if (F3)
            {
                AutoTypeCompletePatchHangLogic("ALL");
                string UploadUser = GetUploadUser();
                httpUtils.ATypeSendERPDataEvent(UploadUser, false);
            }
        }

        private void ChoiseSteelAction(string Code,string Desc,int operIndex)
        {
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
            {
                AssemblyShareData.AUIBlueSectionList[operIndex].Steel.SteelCode = Code;
                AssemblyShareData.AUIBlueSectionList[operIndex].Steel.SteelName = Desc;
                BoardDataGridView.Rows[operIndex].Cells["Steel"].Value = Desc;
            }
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                ManualBoardGridView.Rows[operIndex].Cells["MSteel"].Value = Desc;
        }

        //花式下拉 自动模式就开始渲染数据
        private void FancySelectBox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            CADCommonForm.CategoryStr = (string)FancySelectBox.SelectedItem;
            string itemValue = (string)FancySelectBox.SelectedItem;
            int targetIndex = ParamsConfigData.MoldTypeList.FindIndex(item => item.category.Equals(itemValue));
            if(targetIndex != -1)
            {
                string sysName = ParamsConfigData.MoldTypeList[targetIndex].shortName;
                CADCommonForm.MoldTypeStr = sysName;
            }
            if (OldFancySelectItem == null)
                goto continueLoop;
            if (!OldFancySelectItem.Equals(itemValue))
                goto continueLoop;

            continueLoop:
            {
                if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                    MTypeSearchInitBoardAnditemData();
                BoardDataGridView.Rows.Clear();
                ItemDataGridView.Rows.Clear();
                List<StandardCategoryBoard> FancyPlateList = ParamsConfigData.FancyPlateList;
                List<StandardCategoryBoard> tempList = FancyPlateList.FindAll(item => item.category.Equals(itemValue))
                    .OrderBy(item => item.sortNum).ToList();
                AutoPageResetBoardDataByCategory(tempList);
                OldFancySelectItem = itemValue;
            }
        }

        //切换模式选项卡事件
        private void R2DControl_SelectedIndexChanged(object sender, EventArgs e)
        {
            int TabIndex = this.R2DControl.SelectedIndex;
            if (TabIndex == 0)
                AssemblyShareData.operType = CustomOperPatternType.AUTO;
            if (TabIndex == 1)
                AssemblyShareData.operType = CustomOperPatternType.MANUAL;
            if (TabIndex == 2)
            {
                AssemblyShareData.operType = CustomOperPatternType.TEMP;
                SearchDBTempRecordInfo();
                RenderTempSaveRecordUI();
            }
            ToggleUIShow();
        }

        //切换模式 UI选择性隐藏
        private void ToggleUIShow()
        {
            Boolean AUTOF = AssemblyShareData.operType == CustomOperPatternType.AUTO;
            Boolean TEMPF = AssemblyShareData.operType == CustomOperPatternType.TEMP;
            if (AUTOF || TEMPF)
            {
                IdentifyMoldBtn.Visible = true;
                SpeLabel.Visible = false;
                MoldSizeBox.Visible = false;
                MALabel.Visible = false;
                MBLabel.Visible = false;
                MCLabel.Visible = false;
                MTypeABoardBox.Visible = false;
                MTypeBBoardBox.Visible = false;
                MTypeCBoardBox.Visible = false;
            }
            else
            {
                IdentifyMoldBtn.Visible = false;
                SpeLabel.Visible = true;
                MoldSizeBox.Visible = true;
                MALabel.Visible = true;
                MBLabel.Visible = true;
                MCLabel.Visible = true;
                MTypeABoardBox.Visible = true;
                MTypeBBoardBox.Visible = true;
                MTypeCBoardBox.Visible = true;
            }
            if(!TEMPF)
                TempSaveRecordBtn.Visible = true;
            else
                TempSaveRecordBtn.Visible = false;
        }

        //初始化零件 & 补充零件规格(直径 数量) 按标准
        private void MStandRepItemSep(List<StandardSeriesRelItem> argList, int size)
        {
            List<StandardSeriesRelItem> operList = argList;
            Boolean NoFF = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) == -1;
            if (NoFF)
                operList = operList.FindAll(item => !item.ItemCode.Equals("SpaceBlockScrew")).ToList();
            Boolean NoepfpF = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("epBoard") ||
                                item.BoardCode.Equals("fpBoard")) == -1;
            if (NoepfpF)
                operList = operList.FindAll(item => !item.ItemCode.Equals("PinBoardScrew")).ToList();
            string CMSeries = "通用";
            string MouldSeries = null;
            if (MSYS.Equals("PP"))
                MouldSeries = "细水口";
            if (MSYS.Equals("SG"))
                MouldSeries = "大水口";
            if (MSYS.Equals("TP"))
                MouldSeries = "简化型";
            int nearSize = ComputedUtils.GetMNearMoldSize(size.ToString());
            List<StandardHoleData> originList = ParamsConfigData.MoldHoleList.FindAll(item => 
            item.MouldSize == nearSize && (item.MouldSeries.Equals(CMSeries)
            || item.MouldSeries.Equals(MouldSeries)));

            //规格分类
            if (originList.Count > 0)
            {
                List<StandardHoleData> bigScrewList = originList.FindAll(item => item.Item.Equals("大螺丝")).ToList();
                List<StandardHoleData> smallScrewList = originList.FindAll(item => item.Item.Equals("小螺丝")).ToList();
                List<StandardHoleData> epScrewList = originList.FindAll(item => item.Item.Equals("针板螺丝")).ToList();
                List<StandardHoleData> rpList = originList.FindAll(item => item.Item.Equals("回针")).ToList();
                List<StandardHoleData> spList = originList.FindAll(item => item.Item.Equals("拉杆")).ToList();
                List<StandardHoleData> gpList = originList.FindAll(item => item.Item.Equals("导柱")).ToList();
                List<StandardHoleData> egpList = originList.FindAll(item => item.Item.Equals("中托边")).ToList();
                
                //有方铁 
                if (bigScrewList.Count > 0)
                {
                    bigScrewList = bigScrewList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = bigScrewList.FirstOrDefault();
                    //方铁螺丝
                    List<StandardSeriesRelItem> fangtieScrewList = 
                        operList.FindAll(item => item.ItemCode.Equals("SpaceBlockScrew")).ToList();
                    //面板螺丝
                    List<StandardSeriesRelItem> topPanelScrewList =
                        operList.FindAll(item => item.ItemCode.Equals("TopPanelScrew")).ToList();
                    if (fangtieScrewList.Count > 0)
                    {
                        fangtieScrewList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                    if (topPanelScrewList.Count > 0)
                    {
                        topPanelScrewList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                }

                if (smallScrewList.Count > 0)
                {
                    smallScrewList = smallScrewList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = smallScrewList.FirstOrDefault();
                    //底板螺丝
                    List<StandardSeriesRelItem> targetList = operList.FindAll(item => item.ItemCode.Equals("BottomPanelScrew")).ToList();
                    if (targetList.Count > 0)
                    {
                        targetList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                }

                if (epScrewList.Count > 0)
                {
                    epScrewList = epScrewList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = epScrewList.FirstOrDefault();
                    //针板螺丝
                    List<StandardSeriesRelItem> targetList = operList.FindAll(item => item.ItemCode.Equals("PinBoardScrew")).ToList();
                    if (targetList.Count > 0)
                    {
                        targetList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                }

                if (rpList.Count > 0)
                {
                    rpList = rpList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = rpList.FirstOrDefault();
                    //回针
                    List<StandardSeriesRelItem> targetList = operList.FindAll(item => item.ItemCode.Equals("ReturnPin")).ToList();
                    if (targetList.Count > 0)
                    {
                        targetList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                    MRPAddTeechLogic();
                }

                //处理回针螺丝
                Boolean RPcheckF = MRPScrewBox.Checked;
                if (RPcheckF)
                {
                    StandardSeriesRelItem rpsItem = new StandardSeriesRelItem();
                    rpsItem.ItemCode = "ReturnPinScrew";
                    rpsItem.ItemName = "回针螺丝";
                    int rpIndex = operList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
                    if(rpIndex != -1)
                    {
                        double rpsDim = CU.RPTeechSep(operList[rpIndex].ItemDim);
                        if(rpsDim != -1)
                            rpsItem.ItemDim = (int)rpsDim;
                        rpsItem.ItemNum = operList[rpIndex].ItemNum;
                    }
                    operList.Add(rpsItem);
                }

                if (spList.Count > 0)
                {
                    spList = spList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = spList.FirstOrDefault();
                    //拉杆
                    List<StandardSeriesRelItem> targetList = operList.FindAll(item => item.ItemCode.Equals("SupportPin")).ToList();
                    if (targetList.Count > 0)
                    {
                        targetList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                }

                if (gpList.Count > 0)
                {
                    gpList = gpList.Distinct(new HoleItemComparer()).ToList();
                    StandardHoleData targetItem = gpList.FirstOrDefault();
                    //导柱
                    List<StandardSeriesRelItem> targetList = operList.FindAll(item => item.ItemCode.Equals("GuidePin")).ToList();
                    if (targetList.Count > 0)
                    {
                        targetList.ForEach(item =>
                        {
                            item.ItemDim = targetItem.ItemDim;
                            item.ItemNum = targetItem.ItemNum;
                        });
                    }
                }

                //单独处理套
                for (int i = 0; i < operList.Count; i++)
                {
                    Boolean BushF = operList[i].ItemCode.Contains("Bush");
                    if (BushF)
                    {
                        Boolean GPBF = operList[i].ItemCode.Contains("Guide");
                        Boolean SPBF = operList[i].ItemCode.Contains("SupportPin");
                        Boolean EGPBF = operList[i].ItemCode.Contains("EGP");
                        if (GPBF)
                        {
                            int gpIndex = operList.FindIndex(item => item.ItemCode.Equals("GuidePin"));
                            if (gpIndex != -1)
                            {
                                operList[i].ItemDim = operList[gpIndex].ItemDim;
                                operList[i].ItemNum = operList[gpIndex].ItemNum;
                            }
                        }
                        if (SPBF)
                        {
                            int spIndex = operList.FindIndex(item => item.ItemCode.Equals("SupportPin"));
                            if (spIndex != -1)
                            {
                                operList[i].ItemDim = operList[spIndex].ItemDim;
                                operList[i].ItemNum = operList[spIndex].ItemNum;
                            }
                        }
                    }
                }

            }

            ShareItemData.MItemList = new List<ManualItem>();
            for (int i = 0; i < operList.Count; i++)
            {
                ManualItem Item = new ManualItem();
                Item.ItemUID = operList[i].ItemCode + i;
                Item.ItemCode = operList[i].ItemCode;
                Item.ItemName = operList[i].ItemName;
                Item.ItemNameType = ComputedUtils.SetItemNameTypeByCode(operList[i].ItemCode);
                Item.Dim = operList[i].ItemDim;
                Item.Num = operList[i].ItemNum;
                Item.Remark = operList[i].ItemRemark;
                ShareItemData.MItemList.Add(Item);
            }

        }

        //补充零件长度 按标准
        private void MStandRepItemL()
        {
            List<ManualItem> lists = ShareItemData.MItemList;
            double sumBoardThick = 0;
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            mBoardList = mBoardList.OrderBy(item => item.plateLineNo).ToList();

            //面板螺丝
            int topScrewIndex = lists.FindIndex(item => item.ItemCode.Equals("TopPanelScrew"));
            if (topScrewIndex != -1)
            {
                List<ManualBoardItem> boardList = mBoardList.FindAll(item => item.BoardCode.Trim().Equals("tpBoard"));
                if (boardList.Count > 0)
                    boardList.ForEach(item => sumBoardThick += Convert.ToDouble(item.PlateThick));
                int moreL = MItemMoreL(lists[topScrewIndex].Dim);
                lists[topScrewIndex].L = (int)sumBoardThick + moreL;
            }

            //底板螺丝
            sumBoardThick = 0;
            int bottomScrewIndex = lists.FindIndex(item => item.ItemCode.Equals("BottomPanelScrew"));
            if (bottomScrewIndex != -1)
            {
                List<ManualBoardItem> boardList = mBoardList.FindAll(item => item.BoardCode.Trim().Equals("bpBoard"));
                if (boardList.Count > 0)
                    boardList.ForEach(item => sumBoardThick += Convert.ToDouble(item.PlateThick));
                int moreL = MItemMoreL(lists[bottomScrewIndex].Dim);
                lists[bottomScrewIndex].L = (int)sumBoardThick + moreL;
            }

            //针板螺丝
            sumBoardThick = 0;
            int epScrewIndex = lists.FindIndex(item => item.ItemCode.Equals("PinBoardScrew"));
            if (epScrewIndex != -1)
            {
                Boolean epfpF = mBoardList.FindIndex(item => item.BoardCode.Trim().Equals("epBoard")
                || item.BoardCode.Trim().Equals("fpBoard")) != -1;
                if(epfpF)
                {
                    int firstepIndex = mBoardList.FindIndex(item => item.BoardCode.Trim().Equals("epBoard"));
                    int lastepIndex = mBoardList.FindLastIndex(item => item.BoardCode.Trim().Equals("epBoard"));
                    if(firstepIndex != -1 && lastepIndex != -1)
                    {
                        if(firstepIndex == lastepIndex)
                            sumBoardThick = mBoardList[firstepIndex].PlateThick;
                        else
                        {
                            List<ManualBoardItem> targetComBoardList = mBoardList.GetRange(firstepIndex, lastepIndex - firstepIndex);
                            if (targetComBoardList.Count > 0)
                                targetComBoardList.ForEach(item => sumBoardThick += Convert.ToDouble(item.PlateThick));
                        }
                    }
                }
                int moreL = MItemMoreL(lists[epScrewIndex].Dim);
                lists[epScrewIndex].L = (int)sumBoardThick + moreL;
            }

            //处理 方铁螺丝
            SpaceBlockScrewLLogic();

            //处理回针
            ComputedRPLLogic();

            //处理回针螺丝
            int rpsIndex = lists.FindIndex(item => item.ItemCode.Equals("ReturnPinScrew"));
            if(rpsIndex != -1)
            {
                int stIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                if (stIndex != -1)
                    lists[rpsIndex].L = AssemblyShareData.MSectionList[stIndex].PlateThick + 5;
            }

            //导柱
            int gpIndex = lists.FindIndex(item => item.ItemCode.Equals("GuidePin"));
            if(gpIndex != -1)
            {
                double gpSumThick = 0;
                if (MGPOverspBoardBox.Checked)
                {
                    int stBoardIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("spBoard"));
                    if (stBoardIndex != -1)
                        gpSumThick += mBoardList[stBoardIndex].PlateThick;
                }
                if(MSYS != null)
                {
                    //简化型
                    if (MSYS.Equals("TP"))
                    {
                        //有方铁 直接算方铁
                        int fIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                        if (fIndex != -1)
                        {
                            List<ManualBoardItem> tempBoardList =  mBoardList.GetRange(0, fIndex);
                            tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                            //+方铁/2
                            gpSumThick += mBoardList[fIndex].PlateThick / 2;
                            lists[gpIndex].L = gpSumThick;
                        }
                        //没方铁 直接推荐倒数第二件
                        else
                        {
                            List<ManualBoardItem> tempBoardList = mBoardList.GetRange(0, mBoardList.Count - 2);
                            tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                            lists[gpIndex].L = gpSumThick;
                        }
                    }
                    //大水口 | 细水口
                    if (MSYS.Equals("SG") || MSYS.Equals("PP"))
                    {
                        int aIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                        int bIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                        if(aIndex != -1 && bIndex != -1)
                        {
                        
                            List<ManualBoardItem> tempBoardList = mBoardList.GetRange(aIndex, bIndex - aIndex + 1);
                            tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                            lists[gpIndex].L = gpSumThick;
                        }
                    }
                }
            }

            //拉杆
            int spIndex = lists.FindIndex(item => item.ItemCode.Equals("SupportPin"));
            if(spIndex != -1)
            {
                //有方铁 直接算方铁
                int fIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                if (fIndex != -1)
                {
                    double spSumThick = 0;
                    List<ManualBoardItem> tempBoardList = mBoardList.GetRange(0, fIndex);
                    tempBoardList.ForEach(item => spSumThick += item.PlateThick);
                    //+方铁/2
                    spSumThick += mBoardList[fIndex].PlateThick / 2;
                    lists[spIndex].L = spSumThick;
                }
                //没方铁 直接推荐倒数第二件
                else
                {
                    double spSumThick = 0;
                    List<ManualBoardItem> tempBoardList = mBoardList.GetRange(0, mBoardList.Count - 2);
                    tempBoardList.ForEach(item => spSumThick += item.PlateThick);
                    lists[spIndex].L = spSumThick;
                }
            }

            //中托边
            int egpIndex = lists.FindIndex(item => item.ItemCode.Equals("EGPPin"));
            if(egpIndex != -1)
            {
                List<ManualBoardItem> computedBList = new List<ManualBoardItem>();
                double egpH = 0;
                double egpDim = lists[egpIndex].Dim;
                int fIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
                if (fIndex != -1)
                {
                    computedBList = mBoardList.GetRange(fIndex, mBoardList.Count - fIndex);
                    computedBList = computedBList.FindAll(item => !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
                }
                if (computedBList.Count > 0)
                    foreach (var item in computedBList)
                        egpH += item.PlateThick;

                if (12 <= egpDim && egpDim <= 20)
                    lists[egpIndex].L = (double)egpH + 15;
                if (egpDim >= 25)
                    lists[egpIndex].L = (double)egpH + 20;
            }

            //单独处理套
            for (int i = 0; i < lists.Count; i++)
            {
                Boolean F1 = lists[i].ItemCode.Contains("Bush");
                Boolean F2 = lists[i].ItemCode.Contains("EGPBush");
                if (F1 && !F2)
                {
                    //处理导柱B套 导柱倒装
                    Boolean F3 = lists[i].ItemCode.Equals("GuideBBush") && MGPInverBox.Checked;
                    //置换一下备注
                    if (F3)
                    {
                       int exchangeIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                        if(exchangeIndex == -1)
                            exchangeIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                        if (exchangeIndex != -1)
                            lists[i].Remark = mBoardList[exchangeIndex].BoardCode;
                    }
                    int bIndex = mBoardList.FindIndex(item => item.BoardCode.Equals(lists[i].Remark));
                    if (bIndex != -1)
                        lists[i].L = mBoardList[bIndex].PlateThick;
                }
            }
        }

        private  GarbageSysHolePosData GetGarbageSysHolePosData()
        {
            string MouldStr = this.MoldSizeBox.Text;
            GarbageSysHolePosData Res = new GarbageSysHolePosData();
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;
            List<GarbageSysBoardItem> boardSizes = new List<GarbageSysBoardItem>();
            if(BoardList.Count > 0)
            {
                BoardList.ForEach(item =>
                {
                    GarbageSysBoardItem BItem = new GarbageSysBoardItem();
                    string LJBoardName = BItem.TranBoardNameArg(item.BoardCode);
                    if (!string.Empty.Equals(LJBoardName))
                    {
                        BItem.width = item.PlateWidth;
                        BItem.length = item.PlateLength;
                        BItem.boardName = LJBoardName;
                        BItem.boardNum = item.Num;
                        boardSizes.Add(BItem);
                    }
                });
            }
            List<ManualItem> ItemList = ShareItemData.MItemList;
            List<GarbageSysHolePosItem> holePartPositions = new List<GarbageSysHolePosItem>();
            if(ItemList.Count> 0)
            {
                ItemList.ForEach(item =>
                {
                    GarbageSysHolePosItem FItem = new GarbageSysHolePosItem();
                    string LJPartName = FItem.TranMoldPartArg(item.ItemCode);
                    if (!string.Empty.Equals(LJPartName))
                    {
                        FItem.partUid = item.ItemUID;
                        FItem.moldPart = LJPartName;
                        FItem.partDiam = (int)item.Dim;
                        FItem.holeNum = item.Num;
                        if (item.ItemHW != null)
                            FItem.distanceWidth = (int)item.ItemHW;
                        if (item.ItemHL != null)
                            FItem.distanceLength = (int)item.ItemHL;
                        holePartPositions.Add(FItem);
                    }
                });
            }
            Res.moldType = MouldStr;
            //文档管理的花式值
            string MouldSeries = null;
            if (CADCommonForm.MoldTypeStr.Equals("PP"))
                MouldSeries = "PPG";
            if (CADCommonForm.MoldTypeStr.Equals("SG"))
                MouldSeries = "SG";
            if (CADCommonForm.MoldTypeStr.Equals("TP"))
                MouldSeries = "TPT";
            Res.moldSeries = MouldSeries;
            Res.boardSizes = boardSizes;
            Res.holePartPositions = holePartPositions;
            Res.guidePinReverse = false;
            Res.sourceFrom = "DATA";
            return Res;
        }

        //根据直径大小 决定是 +5 or 10
        private int MItemMoreL(double Dim)
        {
            if (Dim > 20)
                return 10;
            return 5;
        }

        //手动模式查询逻辑
        private void MTypeSearchLogic()
        {
            ClearMCheck();
            string Fancytext = FancySelectBox.Text;
            MSYS = ComputedUtils.GetSYSBreCodeByFancy(Fancytext);
            InitAndReSetManualData();
        }

        //手动模式设置默认方铁厚
        private void MTypeSetFangtieBoxData()
        {
            string Fancytext = FancySelectBox.Text;
            string MouldStr = this.MoldSizeBox.Text.Trim();
            Boolean moldSizeF = int.TryParse(MouldStr, out int moldSize);
            if (moldSizeF)
            {
                int nearMoldSize = ComputedUtils.GetMNearMoldSize(MouldStr);
                List<StandardBoardThick> targetRefThickList = ParamsConfigData.StandardBoardThickList.FindAll(item => item.moldSize == nearMoldSize);
                if(targetRefThickList.Count > 0)
                {
                    int fIndex = targetRefThickList.FindIndex(item => item.boardCode.Equals("fangtie"));
                    if(fIndex != -1)
                        this.MTypeCBoardBox.Value = Convert.ToDecimal(targetRefThickList[fIndex].boardThick);
                }
            }

        }

        //按回车进行 手工模式查询
        private void MoldSizeBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MTypeSetFangtieBoxData();
                MTypeABoardBox.Focus();
                UpDownBase updbText = (UpDownBase)MTypeABoardBox;
                MTypeABoardBox.Select(0, MTypeABoardBox.Text.Length);
                MTypeSearchInitBoardAnditemData();
            }
        }

        private void MTypeABoardBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MTypeBBoardBox.Focus();
                UpDownBase updbText = (UpDownBase)MTypeBBoardBox;
                MTypeBBoardBox.Select(0, MTypeBBoardBox.Text.Length);
                MTypeSearchInitBoardAnditemData();
            }
        }

        private void MTypeBBoardBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MTypeCBoardBox.Focus();
                UpDownBase updbText = (UpDownBase)MTypeCBoardBox;
                MTypeCBoardBox.Select(0, MTypeCBoardBox.Text.Length);
                MTypeSearchInitBoardAnditemData();
            }
        }

        private void MTypeCBoardBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                MTypeSearchInitBoardAnditemData();
        }

        //手动模式 列出数据前 校验填写参数
        private Boolean CheckInitCorArg()
        {
            Boolean Res = false;
            Boolean F1 = MTypeABoardBox.Value > 0;
            Boolean F2 = MTypeBBoardBox.Value > 0;
            Boolean F3 = MTypeCBoardBox.Value > 0;
            string MouldStr = this.MoldSizeBox.Text;
            Boolean moldSizeF = int.TryParse(MouldStr, out int moldSize);
            if (F1 && F2 && F3 && moldSizeF)
                Res = true;
            return Res;
        }

        //手动模式 填写完条件参数后 列出初始数据
        private void MTypeSearchInitBoardAnditemData()
        {
            Boolean F = CheckInitCorArg();
            if(F)
                MTypeSearchLogic(); 
        }

        //清除复选框状态
        private void ClearMCheck()
        {
            MGPInverBox.Checked = false;
            MGPOverspBoardBox.Checked = false;
            MRPOverstBoardBox.Checked = false;
            MfangtieLockspBoardBox.Checked = false;
            MRPAddTeethBox.Checked = false;
            MRPScrewBox.Checked = false;
            MEGPCheckBox.Checked = false;
        }

        //手动模式 重置数据
        private void InitAndReSetManualData(string Type = null)
        {
            string MouldStr = this.MoldSizeBox.Text;
            Boolean moldSizeF = int.TryParse(MouldStr, out int moldSize);
            if (moldSizeF)
            {
                //手动模式 初始化 板
                InitManualBoardData(moldSize);
                if (Type != null)
                    ClearMCheck();
                MTypeCheckOpetionLogic();
                //手动模式 显示数据
                RenderManualBoardUI(AssemblyShareData.MSectionList);
                ClearMItemDataAndUI();
                MtypebuilderAndComputedItem();
            }
        }

        //用户输入花式 型号厚 设置手动界面 板数据
        private void InitManualBoardData(int moldSize)
        {
            string Fancytext = FancySelectBox.Text;
            string MouldStr = this.MoldSizeBox.Text.Trim();
            string widthStr = MouldStr.Substring(0, 2) + "0";
            string lengthStr = MouldStr.Substring(2, MouldStr.Length - 2) + "0";
            double plateLength = double.Parse(lengthStr);
            double plateWidth = double.Parse(widthStr);
            int nearMoldSize = ComputedUtils.GetMNearMoldSize(moldSize.ToString());
            string sysShortName = CADCommonForm.MoldTypeStr;
            List<StandardCategoryBoard> targetList = ParamsConfigData.FancyPlateList.FindAll(item => item.category.Equals(Fancytext)).OrderBy(item => item.sortNum).ToList();
            List<StandardBoardThick> bThickList = ParamsConfigData.StandardBoardThickList.FindAll(
            item => item.moldSize.Equals(nearMoldSize)).ToList();
            AssemblyShareData.MSectionList = new List<ManualBoardItem>();
            //配板 关联 板厚
            if(targetList.Count > 0 && bThickList.Count > 0)
            {
                for(int i = 0; i < targetList.Count; i++)
                {
                    int bIndex = bThickList.FindIndex(item => item.boardCode.Equals(targetList[i].boardCode));
                    if (bIndex != -1)
                        targetList[i].boardThick = bThickList[bIndex].boardThick;
                }
            }
            if (targetList.Count > 0)
            {
                targetList = targetList.OrderBy(item => item.sortNum).ToList();
                Boolean IF = Fancytext.Contains("I");
                for (int i = 0; i < targetList.Count; i++)
                {
                    ManualBoardItem Item = new ManualBoardItem();
                    Item.BoardUID = targetList[i].boardCode + i;
                    Item.BoardCode = targetList[i].boardCode;
                    Item.BoardName = targetList[i].boardName;
                    Item.plateLineNo = targetList[i].sortNum;
                    Item.MBSortNum = i;
                    Item.PlateLength = plateLength;
                    Item.PlateWidth = plateWidth;
                    if(IF)
                    {
                        if (i == 0 || i == targetList.Count - 1)
                        {
                            if(plateWidth >= 450)
                                Item.PlateWidth += 100;
                            else
                                Item.PlateWidth += 50;
                        }
                    }
                    Boolean FF = Item.BoardCode.Equals("fangtie");
                    if (FF)
                        Item.Num = 2;
                    else
                        Item.Num = 1;
                    if (targetList[i].boardThick != null)
                    {
                        List<string> thickList = targetList[i].boardThick.Split(',').ToList();
                        if (thickList.Count == 1)
                            Item.PlateThick = double.Parse(thickList[0]);
                    }
                    Item.Steel.SteelName = "#50";
                    Item.Hanging.Num = 2;
                    AssemblyShareData.MSectionList.Add(Item);
                }
            }
            
            //设置板宽
            for (int i = 0; i < AssemblyShareData.MSectionList.Count; i++)
            {
                MTypeSetFEPFPBoardWLogic(AssemblyShareData.MSectionList[i]);
                //单独设置A/B/方铁厚度
                if (AssemblyShareData.MSectionList[i].BoardCode.Equals("aBoard"))
                    AssemblyShareData.MSectionList[i].PlateThick = double.Parse(MTypeABoardBox.Value.ToString());
                if (AssemblyShareData.MSectionList[i].BoardCode.Equals("bBoard"))
                    AssemblyShareData.MSectionList[i].PlateThick = double.Parse(MTypeBBoardBox.Value.ToString());
                if (AssemblyShareData.MSectionList[i].BoardCode.Equals("fangtie"))
                    AssemblyShareData.MSectionList[i].PlateThick = double.Parse(MTypeCBoardBox.Value.ToString());
            }

            //设置吊令数据
            MTypeSetPullingLogic();
        }

        //手动模式 设置吊令逻辑
        private void MTypeSetPullingLogic(string Type = null)
        {
            string MouldStr = this.MoldSizeBox.Text;
            Boolean isStandardmoldSizeF = true;
            int realmoldSize = int.Parse(MouldStr);
            int targetmoldSize = ComputedUtils.GetMNearMoldSize(MouldStr);
            if (realmoldSize != targetmoldSize)
                isStandardmoldSizeF = false;
            List<ManualBoardItem> operList = AssemblyShareData.MSectionList;
            for (int i = 0; i < operList.Count; i++)
            {
                double pullingDim = CU.MMoldTypePullingRule(MouldStr, operList[i].BoardCode, operList[i].PlateThick, Type);
                if (pullingDim != 0)
                {
                    operList[i].Hanging.HangingParam.Dim = pullingDim;
                    if (operList[i].BoardCode.Equals("fangtie"))
                        operList[i].Hanging.Num = operList[i].Num * 2;
                    else
                        operList[i].Hanging.Num = 2;
                    if (isStandardmoldSizeF)
                        operList[i].Hanging.standardType = StandardType.Standard;
                    else
                        operList[i].Hanging.standardType = StandardType.NonStandard;
                }
                else
                {
                    operList[i].Hanging.HangingParam.Dim = 0;
                    operList[i].Hanging.Num = 0;
                    operList[i].Hanging.standardType = StandardType.Untried;
                }
            }
        }

        //手动模式 删除板 渲染板UI 零件数据&UI需要联动
        private void MTypeDelBoardRenderBoardAndItemUI(List<ManualBoardItem> targetList,string delBoard = null)
        {
            if(delBoard != null)
            {
                //没有方铁
                if (delBoard.Equals("NOF"))
                    MTypeDelItemWhenNoFangtie();
                if (delBoard.Equals("NOEPFP"))
                    MTypeDelItemWhenNoepfp();
            }
            MTypeSetAllItemCosBoardWhenOperBoard();
            RenderManualBoardUI(targetList);
        }

        //没方铁的场景下 需要删除一些零件
        private void MTypeDelItemWhenNoFangtie()
        {
            List<string> noFItemCodeList = new List<string>() { "SpaceBlockScrew", "PinBoardScrew", "ReturnPin", "ReturnPinScrew" };
            if(ShareItemData.MItemList.Count > 0)
                ShareItemData.MItemList = ShareItemData.MItemList.FindAll(item => !noFItemCodeList.Contains(item.ItemCode)).ToList();
            RanderManualItemUIData();
        }
        //没针板的场景下 需要删除的一些零件
        private void MTypeDelItemWhenNoepfp()
        {
            List<string> noFItemCodeList = new List<string>() {"PinBoardScrew", "ReturnPin", "ReturnPinScrew" };
            if (ShareItemData.MItemList.Count > 0)
                ShareItemData.MItemList = ShareItemData.MItemList.FindAll(item => !noFItemCodeList.Contains(item.ItemCode)).ToList();
            RanderManualItemUIData();
        }

        //手动界面 渲染板UI数据
        private void RenderManualBoardUI(List<ManualBoardItem> targetList)
        {
            ManualBoardGridView.Rows.Clear();
            for (int i = 0; i < targetList.Count; i++)
            {
                DataGridView ItemData = new DataGridView();
                int rowIndex = ManualBoardGridView.Rows.Add(ItemData);
                ManualBoardGridView.Rows[rowIndex].Cells["MAddBoardOper"] = new DXButtonCell("+");
                ManualBoardGridView.Rows[rowIndex].Cells["MsubBoardOper"] = new DXButtonCell("-");
                ManualBoardGridView.Rows[rowIndex].Cells["MBUID"].Value = targetList[i].BoardUID;
                ManualBoardGridView.Rows[rowIndex].Cells["MBoardName"].Value = targetList[i].BoardName;
                ManualBoardGridView.Rows[rowIndex].Cells["MSteel"].Value = targetList[i].Steel.SteelName;
                ManualBoardGridView.Rows[rowIndex].Cells["MPlateLength"].Value = targetList[i].PlateLength;
                ManualBoardGridView.Rows[rowIndex].Cells["MPlateWidth"].Value = targetList[i].PlateWidth;
                ManualBoardGridView.Rows[rowIndex].Cells["MPlateThick"].Value = targetList[i].PlateThick;
                ManualBoardGridView.Rows[rowIndex].Cells["MFrameProcess"].Value = targetList[i].frameItem.Tig;
                ManualBoardGridView.Rows[rowIndex].Cells["MNum"].Value = targetList[i].Num;
                //UI设置吊令
                if(targetList[i].Hanging.HangingParam.Dim != 0)
                ManualBoardGridView.Rows[rowIndex].Cells["MHangingDim"].Value = targetList[i].Hanging.HangingParam.Dim;
                if (targetList[i].Hanging.Num != 0)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHangingNum"].Value = targetList[i].Hanging.Num;
                if (targetList[i].Hanging.standardType == StandardType.Untried)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHangingStandard"].Value = "";
                if (targetList[i].Hanging.standardType == StandardType.Standard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHangingStandard"].Value = "标准";
                if (targetList[i].Hanging.standardType == StandardType.NonStandard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHangingStandard"].Value = "非标";
                //UI设置孔距
                if(targetList[i].PitchHoleStandard == StandardType.Standard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHoleStandardNoEGP"].Value = "标准";
                if (targetList[i].PitchHoleStandard == StandardType.NonStandard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MHoleStandardNoEGP"].Value = "非标";
                if (targetList[i].EGPPitchHoleStandard == StandardType.Standard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MEGPHoleStandard"].Value = "标准";
                if (targetList[i].EGPPitchHoleStandard == StandardType.NonStandard)
                    ManualBoardGridView.Rows[rowIndex].Cells["MEGPHoleStandard"].Value = "非标";
            }
        }

        //手动模式 数据&UI 清除
        private void ClearMBoardDataAndUI()
        {
            AssemblyShareData.MSectionList = new List<ManualBoardItem>();
            ManualBoardGridView.Rows.Clear();
        }

        //手动模式 数据&UI 清除
        private void ClearMItemDataAndUI()
        {
            ShareItemData.MItemList = new List<ManualItem>();
            ManualItemGridView.Rows.Clear();
        }



        //用户输入花式 型号厚 设置手动界面 板数据
        private  void SetManualItemSpeAsync(string Fancytext, int moldSize)
        {
            Boolean GPInverF = this.MGPInverBox.Checked;
            Boolean GPOverspF = this.MGPOverspBoardBox.Checked;
            Boolean RPOverstF = this.MRPOverstBoardBox.Checked;
            Boolean fangtieLockspBoardF = this.MfangtieLockspBoardBox.Checked;
            //设置零件
            List<StandardSeriesRelItem> StandardMItemList = ParamsConfigData.StandardBoardRelItemList
                .FindAll(item => item.MouldSeries.Equals(Fancytext)).ToList();
            if (StandardMItemList.Count > 0)
            {
                MStandRepItemSep(StandardMItemList, moldSize);
                MStandRepItemL();
                //初始化这里要覆盖之前的逻辑
                MInitEGPLogic();
                RanderManualItemUIData();
            }
        }

        //手动模式 处理孔距
        private async void LJMPHole()
        {
            if(ShareItemData.MItemList.Count > 0)
            {
                //组织文档管理系统入参
                GarbageSysHolePosData PostData = GetGarbageSysHolePosData();
                List<GarbageSysResDataItem> ResHoleList = await HttpUtils.AskFileSysHoleData(PostData);
                List<ManualItem> operList = ShareItemData.MItemList;
                 if (ResHoleList.Count > 0 && operList.Count > 0)
                 {
                    for(int i = 0; i < operList.Count; i++)
                    {
                        //孔距数据更改
                        int targetLJIndex = ResHoleList.FindIndex(item => item.partUid.Equals(operList[i].ItemUID));
                        if(targetLJIndex != -1)
                        {
                            GarbageSysResDataItem targetLJ = ResHoleList[targetLJIndex];
                            operList[i].ItemHW = targetLJ.distanceWidth;
                            operList[i].ItemHL = targetLJ.distanceLength;
                            if (targetLJ.standardFlag)
                                operList[i].HoleIsStandard = StandardType.Standard;
                            else
                                operList[i].HoleIsStandard = StandardType.NonStandard;
                        }
                    }
                    //设置每件板孔距是否标准
                    MTypeSetBoardHoleStandard();
                    RenderMainWinHoleUI();
                 }
            }
            else
            {
                MessageBox.Show("手动界面没有零件 无法计算孔距!");
                return;
            }
            
        }

        //手动模式 零件页面渲染
        private void RanderManualItemUIData()
        {
            List<ManualItem> MItemList = ShareItemData.MItemList;
            ManualItemGridView.Rows.Clear();
            for (int i = 0; i < MItemList.Count; i++)
            {
                DataGridView ItemData = new DataGridView();
                int rowIndex = ManualItemGridView.Rows.Add(ItemData);
                ManualItemGridView.Rows[rowIndex].Cells["MItemAddOper"] = new DXButtonCell("+");
                ManualItemGridView.Rows[rowIndex].Cells["MItemSubOper"] = new DXButtonCell("-");
                ManualItemGridView.Rows[rowIndex].Cells["MItemUID"].Value = MItemList[i].ItemCode + i;
                ManualItemGridView.Rows[rowIndex].Cells["MItemName"].Value = MItemList[i].ItemName;
                if (MItemList[i].ItemHW != 0)
                    ManualItemGridView.Rows[rowIndex].Cells["HoleW"].Value = MItemList[i].ItemHW;
                if (MItemList[i].ItemHL != 0)
                    ManualItemGridView.Rows[rowIndex].Cells["HoleL"].Value = MItemList[i].ItemHL;
                ManualItemGridView.Rows[rowIndex].Cells["MItemDim"].Value = MItemList[i].Dim;
                ManualItemGridView.Rows[rowIndex].Cells["MItemL"].Value = MItemList[i].L;
                ManualItemGridView.Rows[rowIndex].Cells["MItemNum"].Value = MItemList[i].Num;
            }
        }

        //点击 计算零件按钮前 判断板件厚度是否都有填写
        public AMTypeCheckWarn CheckMBoardThickAllFillOut()
        {
            AMTypeCheckWarn warnInfo = new AMTypeCheckWarn();
            StringBuilder strBuilder = new StringBuilder();
            List<ManualBoardItem> MSectionList = AssemblyShareData.MSectionList;
            for(int i = 0; i < MSectionList.Count; i++)
            {
                Boolean F = MSectionList[i].PlateThick <= 0;
                if (F)
                {
                    warnInfo.warnF = false;
                    string tempStr = MSectionList[i].BoardName + "厚度未正确填写!";
                    strBuilder.AppendLine(tempStr);
                }
            }
            warnInfo.tig = strBuilder.ToString();
            return warnInfo;
        }

        //判断生成&计算零件逻辑
        private AMTypeCheckWarn MtypebuilderAndComputedItem()
        {
            AMTypeCheckWarn warnInfo = CheckMBoardThickAllFillOut();
            if (warnInfo.warnF)
            {
                string Fancytext = FancySelectBox.Text;
                string MouldStr = this.MoldSizeBox.Text;
                Boolean moldSizeF = int.TryParse(MouldStr, out int moldSize);
                //设置零件
                if (moldSizeF)
                {
                    int targetmoldSize = ComputedUtils.GetMNearMoldSize(moldSize.ToString());
                    SetManualItemSpeAsync(Fancytext, targetmoldSize);
                    MRPAddTeechLogic();
                }
                //需要清除板列表关于孔距 全部数据
                MTypeClearMBoardAboutHoleStandrad();
                MTypeSetAllItemCosBoardWhenOperBoard();
            }
            return warnInfo;
        }

        //计算零件 按钮点击事件 选完板件之后 点选计算零件 
        private void MComputedItemBtn_Click(object sender, EventArgs e)
        {
            AMTypeCheckWarn warnInfo = MtypebuilderAndComputedItem();
            if(!warnInfo.warnF)
                MessageBox.Show(warnInfo.tig);
        }

        public void MTypeClearMBoardAboutHoleStandrad()
        {
            List<ManualBoardItem> operList = AssemblyShareData.MSectionList;
            if(operList.Count > 0)
            {
                operList.ForEach(item =>
                {
                    item.PitchHoleStandard = StandardType.Untried;
                    item.EGPPitchHoleStandard = StandardType.Untried;
                });
            }
            if(ManualBoardGridView.Rows.Count > 0)
            {
                for(int i = 0; i < ManualBoardGridView.Rows.Count; i++)
                {
                    ManualBoardGridView.Rows[i].Cells["MEGPHoleStandard"].Value = "";
                    ManualBoardGridView.Rows[i].Cells["MHoleStandardNoEGP"].Value = "";
                }
            }
        }

        //操作了板 根据零件长度实时算 该零件绑定了哪些板
        public void MTypeSetAllItemCosBoardWhenOperBoard()
        {
            ResetSetMBSortNum();
            //根据零件长度 设置关联板件
            if (ShareItemData.MItemList.Count > 0)
                ShareItemData.MItemList.ForEach(item => MTypeMatchItemIncludeBoard(item.ItemUID));
            MTypeSetBoardHoleStandard();
        }

        //手动模式 +-板操作
        private void ManualBoardAddOrSubOper(string ViewOperName)
        {
            List<ManualBoardItem> CheckBList = AssemblyShareData.MSectionList;
            //动态设置板选项
            BSForm.SelectBoardComboBox.DataSource = null;
            if(CADCommonForm.mOperBoardIndex != -1)
            {
                //当前板
                NowOperBoardUID = CheckBList[CADCommonForm.mOperBoardIndex].BoardUID;
                string NowOperBoardCode = CheckBList[CADCommonForm.mOperBoardIndex].BoardCode;
                //+板操作
                if (ViewOperName.Equals("MAddBoardOper"))
                {
                    if (NowOperBoardUID != null)
                    {
                        List<string> MulBCodeList = new List<string>() { "tpBoard", "cpBoard", 
                        "aBoard", "stBoard", "bBoard", "spBoard","bpBoard" };
                        Boolean SampleF = !MulBCodeList.Contains(NowOperBoardCode);
                        //单选项
                        if (SampleF)
                        {
                            if (NowOperBoardCode.Equals("rspBoard"))
                            {
                                List<ManualBoardItem> OperBList = CheckBList;
                                ManualBoardItem Item = new ManualBoardItem();
                                OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
                                int count = OperBList.FindAll(item => item.BoardCode.Equals("rspBoard")).Count();
                                Item.BoardUID = "rspBoard" + count;
                                Item.BoardCode = "rspBoard";
                                Item.ManualOperFlag = true;
                                if (count != 0)
                                    Item.BoardName = "水口推板" + count;
                                else
                                    Item.BoardName = "水口推板";
                                MTypeSetBoardWLLogic(Item);
                                if (count == 0)
                                    OperBList.Insert(CADCommonForm.mOperBoardIndex + 1, Item);
                                else
                                {
                                    int PosIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals("rspBoard"));
                                    OperBList.Insert(PosIndex + 1, Item);
                                }

                                for (int i = 0; i < OperBList.Count; i++)
                                    OperBList[i].plateLineNo = i + 1;

                                CheckBList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                MTypeSetAllItemCosBoardWhenOperBoard();
                                RenderManualBoardUI(AssemblyShareData.MSectionList);
                                
                            }
                            
                            //操作上针板 检测位置 给+下针板
                            if (NowOperBoardCode.Equals("fpBoard"))
                            {
                                Boolean epBCountF = CheckBList.FindAll(item => item.BoardCode.Equals("epBoard")).ToList().Count == 2;
                                if (epBCountF)
                                {
                                    MessageBox.Show("下针板数量已达上限(2) 无法继续+ !");
                                    return;
                                }
                                else
                                {
                                    List<ManualBoardItem> OperBList = CheckBList;
                                    ManualBoardItem Item = new ManualBoardItem();
                                    OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
                                    int count = OperBList.FindAll(item => item.BoardCode.Equals("epBoard")).Count();
                                    Item.BoardUID = "epBoard" + count;
                                    Item.BoardCode = "epBoard";
                                    Item.ManualOperFlag = true;
                                    
                                    if (count != 0)
                                        Item.BoardName = "下针板" + count;
                                    else
                                        Item.BoardName = "下针板";
                                    MTypeSetBoardWLLogic(Item);
                                    if (count == 0)
                                        OperBList.Insert(CADCommonForm.mOperBoardIndex + 1, Item);
                                    else
                                    {
                                        int PosIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                                        OperBList.Insert(PosIndex + 1, Item);
                                    }

                                    for (int i = 0; i < OperBList.Count; i++)
                                        OperBList[i].plateLineNo = i + 1;

                                    CheckBList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                    AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                    MTypeSetAllItemCosBoardWhenOperBoard();
                                    RenderManualBoardUI(AssemblyShareData.MSectionList);
                                }
                            }

                            //操作下针板 比较特殊 一般场景都是往下+  检测位置 往上+ 
                            if (NowOperBoardCode.Equals("epBoard"))
                            {
                                Boolean fpBCountF = CheckBList.FindAll(item => item.BoardCode.Equals("fpBoard")).ToList().Count == 2;
                                if (fpBCountF)
                                {
                                    MessageBox.Show("上针板数量已达上限(2) 无法继续+ !");
                                    return;
                                }
                                else
                                {
                                    List<ManualBoardItem> OperBList = CheckBList;
                                    ManualBoardItem Item = new ManualBoardItem();
                                    OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
                                    int count = OperBList.FindAll(item => item.BoardCode.Equals("fpBoard")).Count();
                                    Item.ManualOperFlag = true;
                                    Item.BoardUID = "fpBoard" + count;
                                    Item.BoardCode = "fpBoard";
                                    if (count != 0)
                                        Item.BoardName = "上针板" + count;
                                    else
                                        Item.BoardName = "上针板";
                                    MTypeSetBoardWLLogic(Item);
                                    if (count == 0)
                                        OperBList.Insert(CADCommonForm.mOperBoardIndex, Item);
                                    else
                                    {
                                        int PosIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                                        OperBList.Insert(PosIndex, Item);
                                    }

                                    for (int i = 0; i < OperBList.Count; i++)
                                        OperBList[i].plateLineNo = i + 1;

                                    CheckBList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                    AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                                    MTypeSetAllItemCosBoardWhenOperBoard();
                                    RenderManualBoardUI(AssemblyShareData.MSectionList);
                                }
                            }

                            ////底板
                            //if (NowOperBoardCode.Equals("bpBoard"))
                            //{
                            //    List<ManualBoardItem> OperBList = CheckBList;
                            //    ManualBoardItem Item = new ManualBoardItem();
                            //    OperBList = OperBList.OrderBy(item => item.plateLineNo).ToList();
                            //    int count = OperBList.FindAll(item => item.BoardCode.Equals("sepBoard")).Count();
                            //    Item.ManualOperFlag = true;
                            //    Item.BoardUID = "sepBoard" + count;
                            //    Item.BoardCode = "sepBoard";
                            //    if (count != 0)
                            //        Item.BoardName = "隔板" + count;
                            //    else
                            //        Item.BoardName = "隔板";
                            //    MTypeSetBoardWLLogic(Item);
                            //    if (count == 0)
                            //        OperBList.Insert(CADCommonForm.mOperBoardIndex, Item);
                            //    else
                            //    {
                            //        int PosIndex = OperBList.FindLastIndex(item => item.BoardCode.Equals("bpBoard"));
                            //        OperBList.Insert(PosIndex, Item);
                            //    }

                            //    for (int i = 0; i < OperBList.Count; i++)
                            //        OperBList[i].plateLineNo = i + 1;

                            //    CheckBList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                            //    AssemblyShareData.MSectionList = (List<ManualBoardItem>)ConvertUtils.DeepCopyObject(OperBList);
                            //    MTypeSetAllItemCosBoardWhenOperBoard();
                            //    RenderManualBoardUI(AssemblyShareData.MSectionList);

                            //}
                        }
                        //多选项
                        else
                        {
                            List<DataGirdViewBoardItem> DGBList = new List<DataGirdViewBoardItem>();
                            if (NowOperBoardCode.Equals("tpBoard"))
                            {
                                int aBoardFirstIndex = CheckBList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                                if (aBoardFirstIndex != -1)
                                {
                                    DataGirdViewBoardItem Item2 = new DataGirdViewBoardItem("sfangtie", "上方铁");
                                    DataGirdViewBoardItem Item3 = new DataGirdViewBoardItem("hrBoard", "热流道板");
                                    DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                    DGBList.Add(Item2);
                                    DGBList.Add(Item3);
                                    DGBList.Add(Item4);
                                }
                            }
                            if (NowOperBoardCode.Equals("cpBoard"))
                            {
                                int aBoardFirstIndex = CheckBList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                                if (aBoardFirstIndex != -1)
                                {
                                    DataGirdViewBoardItem Item2 = new DataGirdViewBoardItem("sfangtie", "上方铁");
                                    DataGirdViewBoardItem Item3 = new DataGirdViewBoardItem("hrBoard", "热流道板");
                                    DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                    DGBList.Add(Item2);
                                    DGBList.Add(Item3);
                                    DGBList.Add(Item4);
                                }
                            }
                            if (NowOperBoardCode.Equals("aBoard"))
                            {
                                DataGirdViewBoardItem Item1 = new DataGirdViewBoardItem("aBoard", "A板");
                                DGBList.Add(Item1);
                                Boolean ExitsfangtieFlag = CheckBList.FindIndex(item => item.BoardCode.Equals("sfangtie")) != -1;
                                //有上方铁
                                if (ExitsfangtieFlag)
                                {
                                    DataGirdViewBoardItem Item2 = new DataGirdViewBoardItem("epBoard", "下针板");
                                    DataGirdViewBoardItem Item3 = new DataGirdViewBoardItem("fpBoard", "上针板");
                                    DGBList.Add(Item2);
                                    DGBList.Add(Item3);
                                }
                                DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                DGBList.Add(Item4);
                                DataGirdViewBoardItem Item5 = new DataGirdViewBoardItem("stBoard", "推板");
                                DGBList.Add(Item5);
                            }
                            if (NowOperBoardCode.Equals("stBoard"))
                            {
                                DataGirdViewBoardItem Item1 = new DataGirdViewBoardItem("stBoard", "推板");
                                DGBList.Add(Item1);
                                DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                DGBList.Add(Item4);
                            }
                            if (NowOperBoardCode.Equals("bBoard"))
                            {
                                DataGirdViewBoardItem Item1 = new DataGirdViewBoardItem("bBoard", "B板");
                                DGBList.Add(Item1);
                                DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                DGBList.Add(Item4);
                            }
                            if (NowOperBoardCode.Equals("spBoard"))
                            {
                                DataGirdViewBoardItem Item1 = new DataGirdViewBoardItem("spBoard", "托板");
                                DGBList.Add(Item1);
                                DataGirdViewBoardItem Item4 = new DataGirdViewBoardItem("mpBoard", "垫板");
                                DGBList.Add(Item4);
                            }
                            BSForm.SelectBoardComboBox.DisplayMember = "BoardName";
                            BSForm.SelectBoardComboBox.ValueMember = "BoardCode";
                            BSForm.SelectBoardComboBox.DataSource = DGBList;
                            ZwSoft.ZwCAD.ApplicationServices.Application.ShowModelessDialog(BSForm);
                        }
                    }
                }
                //-板操作 1.手动+ 可以删掉 2.原花式基础上 针板和方铁可以删掉，其它不删
                if (ViewOperName.Equals("MsubBoardOper"))
                {
                    if (NowOperBoardCode.Equals("fangtie"))
                    {
                        //方铁&=1 连同针板一起删掉
                        int FCount = CheckBList.FindAll(item => item.BoardCode.Equals("fangtie")).Count;
                        if (FCount == 1)
                        {
                            List<ManualBoardItem> fpBList = CheckBList.FindAll(item => item.BoardCode.Equals("fpBoard"));
                            List<ManualBoardItem> epBList = CheckBList.FindAll(item => item.BoardCode.Equals("epBoard"));
                            for (int i = 0; i < fpBList.Count; i++)
                            {
                                int FI = CheckBList.FindIndex(item => item.BoardUID.Equals(fpBList[i].BoardUID));
                                CheckBList.RemoveAt(FI);
                            }
                            for (int i = 0; i < epBList.Count; i++)
                            {
                                int FI = CheckBList.FindIndex(item => item.BoardUID.Equals(epBList[i].BoardUID));
                                CheckBList.RemoveAt(FI);
                            }
                            CheckBList = CheckBList.FindAll(item => !item.BoardCode.Equals("fangtie"));
                        }
                        else
                        {
                            int NowBIndex = CheckBList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                            CheckBList.RemoveAt(NowBIndex);
                            //对方铁UID进行二次调整
                            List<ManualBoardItem> ToCUIDBList = CheckBList.FindAll(item => item.BoardCode.Equals(NowOperBoardCode));
                            if (ToCUIDBList.Count > 0)
                            {
                                int BReSetNo = 0;
                                for (int i = 0; i < ToCUIDBList.Count; i++)
                                {
                                    CheckBList[i].BoardUID = CheckBList[i].BoardCode + BReSetNo;
                                    if (BReSetNo == 0)
                                        CheckBList[i].BoardName = "方铁";
                                    else
                                        CheckBList[i].BoardName = "方铁" + BReSetNo;
                                    BReSetNo++;
                                }
                            }
                        }
                        if (CheckBList != null)
                        {
                            for (int i = 0; i < CheckBList.Count; i++)
                                CheckBList[i].plateLineNo = i + 1;
                            AssemblyShareData.MSectionList = CheckBList;
                            Boolean noFangtieF = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("fangtie")) == -1;
                            if(noFangtieF)
                                MTypeDelBoardRenderBoardAndItemUI(AssemblyShareData.MSectionList,"NOF");
                            else
                                MTypeDelBoardRenderBoardAndItemUI(AssemblyShareData.MSectionList);
                        }
                    }
                    else
                    {
                        int OPerBUIDIndex = CheckBList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                        int NowBCount = CheckBList.FindAll(item => item.BoardCode.Equals(NowOperBoardCode)).Count;
                        string BoardName = CU.SetBoardNameByCode(NowOperBoardCode);
                        int NowBIndex = CheckBList.FindIndex(item => item.BoardUID.Equals(NowOperBoardUID));
                        CheckBList.RemoveAt(NowBIndex);
                        MTypeCheckOpetionLogic();
                        if (CheckBList != null)
                        {
                            for (int i = 0; i < CheckBList.Count; i++)
                                CheckBList[i].plateLineNo = i + 1;
                            Boolean noepfpF = AssemblyShareData.MSectionList.FindIndex(item => 
                            item.BoardCode.Equals("epBoard") || item.BoardCode.Equals("fpBoard")) == -1;
                            if(noepfpF)
                                MTypeDelBoardRenderBoardAndItemUI(AssemblyShareData.MSectionList,"NOEPFP");
                            else
                                MTypeDelBoardRenderBoardAndItemUI(AssemblyShareData.MSectionList);
                        }
                    }
                }
            }
        }

        //手动模式 板 数据有变动 重置UID
        private void ResetMBoardUID()
        {
            List<ManualBoardItem> operList = AssemblyShareData.MSectionList;
            for(int i = 0; i < operList.Count; i++)
                operList[i].BoardUID = operList[i].BoardCode + i;
        }

        //手动模式 零件 数据有变动 重置UID
        private void ResetMItemUID()
        {
            List<ManualItem> operList = ShareItemData.MItemList;
            for (int i = 0; i < operList.Count; i++)
                operList[i].ItemUID = operList[i].ItemCode + i;
        }

        private void ManualItemGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string ViewOperName = ManualItemGridView.Columns[e.ColumnIndex].Name;
            //- 数据源 UI同步删除
            if (ViewOperName.Equals("MItemSubOper"))
            {
                if (e.RowIndex >= 0)
                {
                    var ItemUIDValue = ManualItemGridView.Rows[e.RowIndex].Cells["MItemUID"].Value;
                    if (ItemUIDValue != null)
                    {
                        int rIndex = ShareItemData.MItemList.FindIndex(item => item.ItemUID.Equals(ItemUIDValue));
                        if(rIndex != -1)
                        {
                            ShareItemData.MItemList.RemoveAt(rIndex);
                            ResetMItemUID();
                            //设置每件板孔距是否标准
                            MTypeSetBoardHoleStandard();
                            RenderMainWinHoleUI();
                            RanderManualItemUIData();
                        }
                    }
                }
            }
            //+ 数据源 UI同步添加
            if (ViewOperName.Equals("MItemAddOper"))
            {
                ManualItem Item = new ManualItem();
                Item.ItemCode = "TEMP";
                ShareItemData.MItemList.Add(Item);
                ResetMItemUID();
                RanderManualItemUIData();
            }
        }

        private void ItemDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            string ViewOperName = ItemDataGridView.Columns[e.ColumnIndex].Name;
            string ItemUID = ItemDataGridView.Rows[e.RowIndex].Cells["ItemUID"].Value.ToString();
            if (ViewOperName.Equals("ItemOperMDim"))
                MeasureDWGItemDim(e.RowIndex, "AUTOAUTO");

            if (ViewOperName.Equals("ItemOperMLength"))
            {
                Boolean spF = ItemUID.Equals("SupportPin") || ItemUID.Equals("NoNozzleMesonSupportPin");
                Boolean gpF = ItemUID.Equals("GuidePin");
                Boolean rpF = ItemUID.Equals("ReturnPin");
                if (spF || gpF || rpF)
                {
                    this.WindowState = FormWindowState.Minimized;
                    MeasureDWGItemL(e.RowIndex, "AUTOAUTO");
                }
                else
                    MessageBox.Show("仅针对拉杆导柱回针!");
            }
        }

        private void ManualBoardGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            string ViewOperName = ManualBoardGridView.Columns[e.ColumnIndex].Name;
            if (ViewOperName.Equals("MmeasureOper"))
                DrawLBThickAndWidth(e.RowIndex);
        }

        private void SurplusItemDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            string ViewOperName = SurplusItemDataGridView.Columns[e.ColumnIndex].Name;
            
            //点击测量D
            if (ViewOperName.Equals("SMItemDim"))
            {
                this.WindowState = FormWindowState.Minimized;
                MeasureDWGItemDim(e.RowIndex, "AUTOM");
            }
            //点击测量L
            if (ViewOperName.Equals("SMItemLength"))
            {
                this.WindowState = FormWindowState.Minimized;
                string ItemName = SurplusItemDataGridView.Rows[e.RowIndex].Cells["SurplusItemName"].Value.ToString();
                if (ItemName.Contains("拉杆") || ItemName.Contains("导柱") || ItemName.Contains("回针"))
                {
                    this.WindowState = FormWindowState.Minimized;
                    MeasureDWGItemL(e.RowIndex, "AUTOM");
                }
                else
                    MessageBox.Show("仅针对拉杆导柱回针!");
            }
        }

        private void ManualItemGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if(e.RowIndex >= 0)
            {
                string ItemName = string.Empty;
                string ViewOperName = ManualItemGridView.Columns[e.ColumnIndex].Name;
                var MItemNameCell = ManualItemGridView.Rows[e.RowIndex].Cells["MItemName"].Value;
                if(MItemNameCell != null)
                    ItemName = MItemNameCell.ToString();
                // Dim
                if (ViewOperName.Equals("MItemMDim"))
                {
                    if (!string.Empty.Equals(ItemName))
                    {
                        this.WindowState = FormWindowState.Minimized;
                        MeasureDWGItemDim(e.RowIndex, "M");
                    }
                }
                //L
                if (ViewOperName.Equals("MitemML"))
                {
                    this.WindowState = FormWindowState.Minimized;
                    if (!string.Empty.Equals(ItemName))
                    {
                        if (ItemName.Contains("拉杆") || ItemName.Contains("导柱") || ItemName.Contains("回针"))
                        {
                            this.WindowState = FormWindowState.Minimized;
                            MeasureDWGItemL(e.RowIndex, "M");
                        }
                        else
                            MessageBox.Show("仅针对拉杆导柱回针!");
                    }
                }
            }
        }

        //手动模式 板表格 修改数据 触发事件
        private void ManualBoardGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                string BoardUID = string.Empty;
                var MBUIDCell = ManualBoardGridView.Rows[e.RowIndex].Cells["MBUID"].Value;
                if (MBUIDCell != null)
                    BoardUID = MBUIDCell.ToString();
                if (!string.Empty.Equals(BoardUID))
                {
                    int targetIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardUID.Equals(BoardUID));
                    if (targetIndex != -1)
                    {
                        string ViewOperName = ManualBoardGridView.Columns[e.ColumnIndex].Name;
                        if (ViewOperName.Equals("MPlateWidth"))
                        {
                            Object targetPlateWidth = ManualBoardGridView.Rows[e.RowIndex].Cells["MPlateWidth"].Value;
                            if (targetPlateWidth != null)
                            {
                                Boolean F = Double.TryParse(targetPlateWidth.ToString(), out double resWidth);
                                if (F)
                                    AssemblyShareData.MSectionList[targetIndex].PlateWidth = resWidth;
                            }
                        }

                        if (ViewOperName.Equals("MPlateLength"))
                        {
                            Object targetPlateLength = ManualBoardGridView.Rows[e.RowIndex].Cells["MPlateLength"].Value;
                            if (targetPlateLength != null)
                            {
                                Boolean F = Double.TryParse(targetPlateLength.ToString(), out double resLength);
                                if (F)
                                    AssemblyShareData.MSectionList[targetIndex].PlateLength = resLength;
                            }
                        }

                        if (ViewOperName.Equals("MPlateThick"))
                        {
                            Object targetPlateThick = ManualBoardGridView.Rows[e.RowIndex].Cells["MPlateThick"].Value;
                            if (targetPlateThick != null)
                            {
                                Boolean F = Double.TryParse(targetPlateThick.ToString(), out double resThick);
                                if (F)
                                {
                                    AssemblyShareData.MSectionList[targetIndex].PlateThick = resThick;
                                    MTypeSetPullingLogic();
                                    ReRenderPullingUI();
                                    ResetItemLAndRanderUI();
                                }
                            }
                        }

                        if (ViewOperName.Equals("MSteel"))
                        {
                            Object targetMSteel = ManualBoardGridView.Rows[e.RowIndex].Cells["MSteel"].Value;
                            if (targetMSteel != null)
                            {
                                AssemblyShareData.MSectionList[targetIndex].Steel.SteelName = targetMSteel.ToString();
                                ResetItemLAndRanderUI();
                            }
                        }

                        if (ViewOperName.Equals("MNum"))
                        {
                            Object targetMNum = ManualBoardGridView.Rows[e.RowIndex].Cells["MNum"].Value;
                            if (targetMNum != null)
                            {
                                Boolean F = int.TryParse(targetMNum.ToString(), out int resNum);
                                if (F)
                                    AssemblyShareData.MSectionList[targetIndex].Num = resNum;
                            }
                        }

                        //吊令 & Num & 是否标准 也从界面拿
                        if (ViewOperName.Equals("MHangingDim"))
                        {
                            var HangingDimValue = ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingDim"].Value;
                            if (HangingDimValue != null)
                                if (double.TryParse(HangingDimValue.ToString(), out double result))
                                {
                                    double targetPullingDim = double.Parse(HangingDimValue.ToString());
                                    AssemblyShareData.MSectionList[targetIndex].Hanging.HangingParam.Dim = targetPullingDim;
                                    ManualBoardItem targetB = AssemblyShareData.MSectionList[e.RowIndex];
                                    string MouldStr = this.MoldSizeBox.Text;
                                    double pullingDim = CU.MMoldTypePullingRule(MouldStr, targetB.BoardCode, targetB.PlateThick);
                                    //直接判定为非标
                                    if(pullingDim == 0)
                                    {
                                        AssemblyShareData.MSectionList[targetIndex].Hanging.standardType = StandardType.NonStandard;
                                        ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingStandard"].Value = "非标";
                                    }
                                    else
                                    {
                                        if(targetPullingDim != pullingDim)
                                        {
                                            AssemblyShareData.MSectionList[targetIndex].Hanging.standardType = StandardType.NonStandard;
                                            ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingStandard"].Value = "非标";
                                        }
                                        else
                                        {
                                            AssemblyShareData.MSectionList[targetIndex].Hanging.standardType = StandardType.Standard;
                                            ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingStandard"].Value = "标准";
                                        }
                                    }
                                }
                        }

                        if (ViewOperName.Equals("MHangingNum"))
                        {
                            var HangingNumValue = ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingNum"].Value;
                            if (HangingNumValue != null)
                            {
                                string hnValue = HangingNumValue.ToString();
                                if (int.TryParse(hnValue.ToString(), out int result))
                                    AssemblyShareData.MSectionList[targetIndex].Hanging.Num = int.Parse(hnValue.ToString());
                            }
                        }

                        if (ViewOperName.Equals("MHangingStandard"))
                        {
                            var HangingHoleValue = ManualBoardGridView.Rows[e.RowIndex].Cells["MHangingStandard"].Value;
                            if (HangingHoleValue != null)
                            {
                                string hangValue = HangingHoleValue.ToString();
                                if (hangValue.Equals("标准"))
                                    AssemblyShareData.MSectionList[targetIndex].Hanging.standardType = StandardType.Standard;
                                if (hangValue.Equals("非标"))
                                    AssemblyShareData.MSectionList[targetIndex].Hanging.standardType = StandardType.NonStandard;
                            }
                        }

                    }
                }
            }
        }
        
        //厚度的变化会引起 吊令UI的变化 为了屏蔽UI循环依赖
        private void ReRenderPullingUI()
        {
            List<ManualBoardItem> BList = AssemblyShareData.MSectionList;
            for (int i = 0; i < ManualBoardGridView.Rows.Count; i++)
            {
                string MBUID = ManualBoardGridView.Rows[i].Cells["MBUID"].Value.ToString();
                int targetBIndex = BList.FindIndex(item => item.BoardUID.Equals(MBUID));
                if (targetBIndex != -1)
                {
                    ManualBoardItem targetBoard = BList[targetBIndex];
                    StandardType ps = targetBoard.Hanging.standardType;
                    if (ps == StandardType.Untried)
                        ManualBoardGridView.Rows[i].Cells["MHangingStandard"].Value = "";
                    if (ps == StandardType.Standard)
                        ManualBoardGridView.Rows[i].Cells["MHangingStandard"].Value = "标准";
                    if (ps == StandardType.NonStandard)
                        ManualBoardGridView.Rows[i].Cells["MHangingStandard"].Value = "非标";
                    double Dim = BList[i].Hanging.HangingParam.Dim;
                    int Num = BList[i].Hanging.Num;
                    if (Num == 0)
                        ManualBoardGridView.Rows[i].Cells["MHangingNum"].Value = "";
                    else
                        ManualBoardGridView.Rows[i].Cells["MHangingNum"].Value = Num;
                    if (Dim == 0)
                        ManualBoardGridView.Rows[i].Cells["MHangingDim"].Value = "";
                    else
                        ManualBoardGridView.Rows[i].Cells["MHangingDim"].Value = Dim;
                }
            }
        }

        //手动模式 零件表格 修改数据 触发事件
        private void ManualItemGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                string ItemUID = string.Empty;
                var MItemUIDCell = ManualItemGridView.Rows[e.RowIndex].Cells["MItemUID"].Value;
                if (MItemUIDCell != null)
                    ItemUID = MItemUIDCell.ToString();
                if (!string.Empty.Equals(ItemUID))
                {
                    int targetIndex = ShareItemData.MItemList.FindIndex(item => item.ItemUID.Equals(ItemUID));
                    if(targetIndex != -1) 
                    {
                        string ViewOperName = ManualItemGridView.Columns[e.ColumnIndex].Name;
                        if (ViewOperName.Equals("MItemName"))
                        {
                            Object targetMItemName = ManualItemGridView.Rows[e.RowIndex].Cells["MItemName"].Value;
                            if (targetMItemName != null)
                            {
                                ShareItemData.MItemList[targetIndex].ItemName = targetMItemName.ToString();
                                ShareItemData.MItemList[targetIndex].ItemCode = CU.SetItemCodeByItemName(targetMItemName.ToString());
                                ShareItemData.MItemList[targetIndex].ItemNameType = ComputedUtils.SetItemNameTypeByCode(ShareItemData.MItemList[targetIndex].ItemCode);
                            }
                            else
                                ShareItemData.MItemList[targetIndex].ItemName = string.Empty;
                            ResetMItemUID();
                            if(ManualItemGridView.Rows.Count > 0)
                                for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
                                    ManualItemGridView.Rows[i].Cells["MItemUID"].Value = ShareItemData.MItemList[i].ItemUID;
                        }
                        if (ViewOperName.Equals("MItemDim"))
                        {
                            Object targetMItemDim = ManualItemGridView.Rows[e.RowIndex].Cells["MItemDim"].Value;
                            if (targetMItemDim != null)
                            {
                                Boolean F = Double.TryParse(targetMItemDim.ToString(), out double resDim);
                                if (F)
                                {
                                    ShareItemData.MItemList[targetIndex].Dim = resDim;
                                    Boolean GPF = ItemUID.Contains("GuidePin");
                                    if (GPF)
                                    {
                                        if (ManualItemGridView.Rows.Count > 0)
                                        {
                                            for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
                                            {
                                                string tempItemUID = ManualItemGridView.Rows[i].Cells["MItemUID"].Value.ToString();
                                                Boolean GPBushF = tempItemUID.Contains("Bush") && tempItemUID.Contains("Guide");
                                                if (GPBushF)
                                                {
                                                    ManualItemGridView.Rows[i].Cells["MItemDim"].Value = resDim;
                                                    int cadeIndex = ShareItemData.MItemList.FindIndex(item => item.ItemUID.Equals(tempItemUID));
                                                    ShareItemData.MItemList[cadeIndex].Dim = resDim;
                                                }
                                            }
                                        }
                                    }
           
                                    Boolean SPF = ItemUID.Contains("SupportPin") && !ItemUID.Contains("Bush");
                                    if (SPF)
                                    {
                                        if (ManualItemGridView.Rows.Count > 0)
                                        {
                                            for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
                                            {
                                                string tempItemUID = ManualItemGridView.Rows[i].Cells["MItemUID"].Value.ToString();
                                                Boolean SPBushF = tempItemUID.Contains("Bush") && tempItemUID.Contains("SupportPin");
                                                if (SPBushF)
                                                {
                                                    ManualItemGridView.Rows[i].Cells["MItemDim"].Value = resDim;
                                                    int cadeIndex = ShareItemData.MItemList.FindIndex(item => item.ItemUID.Equals(tempItemUID));
                                                    ShareItemData.MItemList[cadeIndex].Dim = resDim;
                                                }
                                            }
                                        }
                                    }

                                }
                            }
                        }

                        //长度发生变化 零件穿过哪些板也要重新计算
                        if (ViewOperName.Equals("MItemL"))
                        {
                            Object targetMItemL = ManualItemGridView.Rows[e.RowIndex].Cells["MItemL"].Value;
                            if (targetMItemL != null)
                            {
                                Boolean F = Double.TryParse(targetMItemL.ToString(), out double resL);
                                if (F)
                                {
                                    double oldL = ShareItemData.MItemList[targetIndex].L;
                                    if(oldL != resL)
                                    {
                                        ShareItemData.MItemList[targetIndex].L = resL;
                                        MTypeMatchItemIncludeBoard(ShareItemData.MItemList[targetIndex].ItemUID);
                                    }
                                }
                            }
                        }
                        if (ViewOperName.Equals("MItemNum"))
                        {
                            Object targetMItemNum = ManualItemGridView.Rows[e.RowIndex].Cells["MItemNum"].Value;
                            if (targetMItemNum != null)
                            {
                                Boolean F = int.TryParse(targetMItemNum.ToString(), out int resNum);
                                if (F)
                                    ShareItemData.MItemList[targetIndex].Num = resNum;
                            }
                        }

                        //孔距
                        if (ViewOperName.Equals("HoleW"))
                        {
                            Object targetMItemHoleW = ManualItemGridView.Rows[e.RowIndex].Cells["HoleW"].Value;
                            if (targetMItemHoleW != null)
                            {
                                Boolean F = double.TryParse(targetMItemHoleW.ToString(), out double resHoleW);
                                if (F)
                                    ShareItemData.MItemList[targetIndex].ItemHW = resHoleW;
                            }
                        }

                        if (ViewOperName.Equals("HoleL"))
                        {
                            Object targetMItemHoleL = ManualItemGridView.Rows[e.RowIndex].Cells["HoleL"].Value;
                            if (targetMItemHoleL != null)
                            {
                                Boolean F = double.TryParse(targetMItemHoleL.ToString(), out double resHoleL);
                                if (F)
                                    ShareItemData.MItemList[targetIndex].ItemHL = resHoleL;
                            }
                        }


                        if (ViewOperName.Equals("MItemRemark"))
                        {
                            Object targetMItemRemark = ManualItemGridView.Rows[e.RowIndex].Cells["MItemRemark"].Value;
                            if (targetMItemRemark != null)
                                ShareItemData.MItemList[targetIndex].UIRemark = targetMItemRemark.ToString();
                            else
                                ShareItemData.MItemList[targetIndex].UIRemark = string.Empty;
                        }
                    }
                }
            }
        }

        //重新计算零件长度 并渲染长度UI数据
        private void ResetItemLAndRanderUI()
        {
            MStandRepItemL();
            if (ShareItemData.MItemList.Count > 0)
                for (int i = 0; i < ShareItemData.MItemList.Count; i++)
                {
                    if(ManualItemGridView.Rows.Count > i)
                    ManualItemGridView.Rows[i].Cells["MItemL"].Value = ShareItemData.MItemList[i].L;
                }
        }

        //手动模式 回针加牙 复选框事件
        private void MRPAddTeethBox_CheckedChanged(object sender, EventArgs e)
        {
            MRPAddTeechLogic();
        }

        //回针加牙逻辑
        private void MRPAddTeechLogic()
        {
            Boolean RPTeechcheckF = MRPAddTeethBox.Checked;
            int rpIndex = ShareItemData.MItemList.FindIndex(item => item.ItemName.Equals("回针"));
            if (rpIndex != -1)
            {
                if (RPTeechcheckF)
                {
                    double rpDim = ShareItemData.MItemList[rpIndex].Dim;
                    double RPremark = CU.RPTeechSep(rpDim);
                    if (RPremark != -1)
                    {
                        ShareItemData.MItemList[rpIndex].UIRemark = "M" + RPremark;
                        ManualItemGridView.Rows[rpIndex].Cells["MItemRemark"].Value = "M" + RPremark;
                    }
                }
                else
                {
                    ShareItemData.MItemList[rpIndex].UIRemark = "";
                    ManualItemGridView.Rows[rpIndex].Cells["MItemRemark"].Value = "";
                }
            }
        }

        //手动模式 回针螺丝  复选框事件 
        private void MRPScrewBox_CheckedChanged(object sender, EventArgs e)
        {
            Boolean RPcheckF = MRPScrewBox.Checked;
            int rpIndex = ShareItemData.MItemList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
            if (RPcheckF && rpIndex != -1)
            {
                if(ShareItemData.MItemList.Count > 0)
                {
                    double rpDim = ShareItemData.MItemList[rpIndex].Dim;
                    double RPremark = CU.RPTeechSep(rpDim);
                    ManualItem rpScrewItem = new ManualItem();
                    rpScrewItem.ItemName = "回针螺丝";
                    rpScrewItem.ItemCode = "ReturnPinScrew";
                    if (RPremark != -1)
                        rpScrewItem.Dim = RPremark;
                    //暂定 回针螺丝=推板厚度+5
                    int stIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                    if(stIndex != -1)
                        rpScrewItem.L = AssemblyShareData.MSectionList[stIndex].PlateThick + 5;
                    ShareItemData.MItemList.Add(rpScrewItem);
                    ResetMItemUID();
                    RanderManualItemUIData();
                }
            }
            else
            {
                int rpScrewIndex = ShareItemData.MItemList.FindIndex(item => item.ItemCode.Equals("ReturnPinScrew"));
                if(rpScrewIndex != -1)
                {
                    ShareItemData.MItemList.RemoveAt(rpScrewIndex);
                    ResetMItemUID();
                    RanderManualItemUIData();
                }
            }
            MRPAddTeechLogic();
        }

        //手动模式 初始化 中托边参数 
        private void MInitSetEGPArg(ManualItem egpItem)
        {
            string MouldStr = this.MoldSizeBox.Text;
            string CMSeries = "通用";
            string MouldSeries = null;
            if (MSYS.Equals("PP"))
                MouldSeries = "细水口";
            if (MSYS.Equals("SG"))
                MouldSeries = "大水口";
            if (MSYS.Equals("TP"))
                MouldSeries = "简化型";
            //靠近标准
            int nearSize = ComputedUtils.GetMNearMoldSize(MouldStr.ToString());
            List<StandardHoleData> originList = ParamsConfigData.MoldHoleList.FindAll(item =>
            item.MouldSize == nearSize && (item.MouldSeries.Equals(CMSeries)
            || item.MouldSeries.Equals(MouldSeries)));
            List<StandardHoleData> egpList = originList.FindAll(item => item.Item.Equals("中托边")).ToList();
            if (egpList.Count > 0)
            {
                int tempEGPDim = egpList.Select(item => item.ItemDim).Distinct().ToList().FirstOrDefault();
                double egpL = egpList.Select(item => item.ItemY).Distinct().ToList().FirstOrDefault();
                egpItem.Dim = tempEGPDim;
                egpItem.Num = egpList[0].ItemNum;
            }
            List<ManualItem> lists = ShareItemData.MItemList;
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            mBoardList = mBoardList.OrderBy(item => item.plateLineNo).ToList();

            List<ManualBoardItem> computedBList = new List<ManualBoardItem>();
            double egpH = 0;
            double egpDim = egpItem.Dim;
            int fIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("fangtie"));
            if(fIndex != -1)
            {
                computedBList = mBoardList.GetRange(fIndex, mBoardList.Count  - fIndex);
                computedBList = computedBList.FindAll(item => !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
            }
                if (computedBList.Count > 0)
                    foreach (var item in computedBList)
                        egpH += item.PlateThick;
            
            if (12 <= egpDim && egpDim <= 20)
                    egpItem.L = (double)egpH + 15;
            if (egpDim >= 25)
                egpItem.L = (double)egpH + 20;
        }

        //中托司参数逻辑
        private void SetEGPBushArg(ManualItem egpBushItem)
        {
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            List<ManualItem> Itemlists = ShareItemData.MItemList;
            List<ManualBoardItem> epfpBoardList = mBoardList.FindAll(item => item.BoardCode.Equals("epBoard")
            || item.BoardCode.Equals("fpBoard")).ToList();
            if (epfpBoardList.Count > 0)
            {
                int TempTheoryH = Convert.ToInt32(epfpBoardList.Sum(item => item.PlateThick)) - 5;
                egpBushItem.L = CU.GPLessThan200TheoryLRepRule(TempTheoryH);
            }
            if(Itemlists.Count > 0)
            {
                int egpIndex = Itemlists.FindIndex(item => item.ItemCode.Equals("EGPPin"));
                if (egpIndex != -1)
                {
                    egpBushItem.Dim = Itemlists[egpIndex].Dim;
                    egpBushItem.Num = Itemlists[egpIndex].Num;
                }
            }
        }

        //EGP逻辑
        private void MInitEGPLogic()
        {
            Boolean EGPcheckF = MEGPCheckBox.Checked;
            if (EGPcheckF)
            {
                ManualItem egpItem = new ManualItem();
                egpItem.ItemName = "中托边";
                egpItem.ItemCode = "EGPPin";
                ManualItem egpBushItem = new ManualItem();
                egpBushItem.ItemName = "中托司";
                egpBushItem.ItemCode = "EGPBush";
                MInitSetEGPArg(egpItem);
                ShareItemData.MItemList.Add(egpItem);
                SetEGPBushArg(egpBushItem);
                ShareItemData.MItemList.Add(egpBushItem);
                ResetMItemUID();
                RanderManualItemUIData();
            }
            else
            {
                int egpIndex = ShareItemData.MItemList.FindIndex(item => item.ItemCode.Equals("EGPPin"));
                if (egpIndex != -1)
                    ShareItemData.MItemList.RemoveAt(egpIndex);
                int egpbushIndex = ShareItemData.MItemList.FindIndex(item => item.ItemCode.Equals("EGPBush"));
                if (egpbushIndex != -1)
                    ShareItemData.MItemList.RemoveAt(egpbushIndex);
                if(egpIndex != -1 || egpbushIndex != -1)
                {
                    ResetMItemUID();
                    RanderManualItemUIData();
                }
            }
        }

        private void MEGPCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if(ShareItemData.MItemList.Count > 0)
                MInitEGPLogic();
            MRPAddTeechLogic();
        }

        private void dxButton1_Click(object sender, EventArgs e)
        {

        }

        private void ManualBoardGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            CADCommonForm.mOperBoardIndex = e.RowIndex;
            string ViewOperName = ManualBoardGridView.Columns[e.ColumnIndex].Name;
            //+ - 板
            if (ViewOperName.Equals("MAddBoardOper") || ViewOperName.Equals("MsubBoardOper"))
                ManualBoardAddOrSubOper(ViewOperName);
            //设置材质
            if (ViewOperName.Equals("MSteel"))
                steelWindow.SetOriginOption(e.RowIndex);
            //精框加工
            if (ViewOperName.Equals("MFrameProcess"))
                frameWindow.InitFrameWindow(e.RowIndex);
        }

        //手动模式 板变动 影响复选项是否可选 逻辑
        private void MTypeCheckOpetionLogic()
        {
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            //没推板 回针螺丝 回针加牙 不开放
            Boolean nostF = mBoardList.FindIndex(item => item.BoardCode.Equals("stBoard")) == -1;
            if (nostF)
            {
                MRPOverstBoardBox.Checked = false;
                MRPAddTeethBox.Checked = false;
                MRPScrewBox.Checked = false;
                MRPOverstBoardBox.Enabled = false;
                MRPAddTeethBox.Enabled = false;
                MRPScrewBox.Enabled = false;
            }
            else
            {
                MRPOverstBoardBox.Enabled = true;
                MRPAddTeethBox.Enabled = true;
                MRPScrewBox.Enabled = true;
            }
            //没有托板
            Boolean nospF = mBoardList.FindIndex(item => item.BoardCode.Equals("stBoard")) == -1;
            if (nospF)
            {
                MGPOverspBoardBox.Enabled = false;
                MfangtieLockspBoardBox.Enabled = false;
            }
            else
            {
                MGPOverspBoardBox.Enabled = true;
                MfangtieLockspBoardBox.Enabled = true;
            }
               
        }

        //手动模式 导柱倒装逻辑
        private void GPInver()
        {
            if (MGPInverBox.Checked)
            {
                List<ManualItem> lists = ShareItemData.MItemList;
                List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
                int gpBBushIndex = lists.FindIndex(item => item.ItemCode.Equals("GuideBBush"));
                //处理导柱B套 导柱倒装 aBoard ->   bBoard || stBoard
                if (gpBBushIndex != -1)
                {
                    int exchangeIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                    if (exchangeIndex == -1)
                        exchangeIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("stBoard"));
                    if (exchangeIndex != -1)
                        lists[gpBBushIndex].Remark = mBoardList[exchangeIndex].BoardCode;
                    int bIndex = mBoardList.FindIndex(item => item.BoardCode.Equals(lists[gpBBushIndex].Remark));
                    if (bIndex != -1)
                        lists[gpBBushIndex].L = mBoardList[bIndex].PlateThick;
                }
            }
            else
            {
                //取消 B套备注 -> aBoard
                List<ManualItem> lists = ShareItemData.MItemList;
                List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
                int gpBBushIndex = lists.FindIndex(item => item.ItemCode.Equals("GuideBBush"));
                if (gpBBushIndex != -1)
                {
                    lists[gpBBushIndex].Remark = "aBoard";
                    int bIndex = mBoardList.FindIndex(item => item.BoardCode.Equals(lists[gpBBushIndex].Remark));
                    if (bIndex != -1)
                        lists[gpBBushIndex].L = mBoardList[bIndex].PlateThick;
                }
            }
            RanderManualItemUIData();
        }

        //手动模式 导柱反装 复选事件
        private void MGPInverBox_CheckedChanged(object sender, EventArgs e)
        {
            GPInver();
        }

        //手动模式 导柱过托 复选事件
        private void MGPOverspBoardBox_CheckedChanged(object sender, EventArgs e)
        {
            List<ManualItem> lists = ShareItemData.MItemList;
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            mBoardList = mBoardList.OrderBy(item => item.plateLineNo).ToList();
            //导柱
            int gpIndex = lists.FindIndex(item => item.ItemCode.Equals("GuidePin"));
            if (gpIndex != -1)
            {
                double gpSumThick = 0;
                if (MGPOverspBoardBox.Checked)
                {
                    int stBoardIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("spBoard"));
                    if (stBoardIndex != -1)
                        gpSumThick += mBoardList[stBoardIndex].PlateThick;
                }
                //简化型
                if (MSYS.Equals("TP"))
                {
                    //有方铁 直接算方铁
                    int fIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                    if (fIndex != -1)
                    {
                        List<ManualBoardItem> tempBoardList = mBoardList.GetRange(0, fIndex);
                        tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                        //+方铁/2
                        gpSumThick += mBoardList[fIndex].PlateThick / 2;
                        lists[gpIndex].L = gpSumThick;
                    }
                    //没方铁 直接推荐倒数第二件
                    else
                    {
                        List<ManualBoardItem> tempBoardList = mBoardList.GetRange(0, mBoardList.Count - 2);
                        tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                        lists[gpIndex].L = gpSumThick;
                    }
                }
                //大水口 | 细水口
                if (MSYS.Equals("SG") || MSYS.Equals("PP"))
                {
                    int aIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("aBoard"));
                    int bIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("bBoard"));
                    if (aIndex != -1 && bIndex != -1)
                    {

                        List<ManualBoardItem> tempBoardList = mBoardList.GetRange(aIndex, bIndex - aIndex + 1);
                        tempBoardList.ForEach(item => gpSumThick += item.PlateThick);
                        lists[gpIndex].L = gpSumThick;
                    }
                }
                RanderManualItemUIData();
                MRPAddTeechLogic();
            }
        }

        //回针长度计算逻辑
        private void ComputedRPLLogic()
        {
            Boolean mpoverstF = MRPOverstBoardBox.Checked;
            double sumBoardThick = 0;
            List<ManualItem> lists = ShareItemData.MItemList;
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            //处理回针
            int rpIndex = lists.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
            if (rpIndex != -1)
            {
                int startIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("bBoard"));
                if (startIndex == -1)
                {
                    startIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("stBoard"));
                    if (startIndex == -1)
                        startIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("aBoard"));
                }
                if(mpoverstF)
                    startIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("stBoard"));
                int endIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("fpBoard"));
                if (endIndex == -1)
                    endIndex = mBoardList.FindLastIndex(item => item.BoardCode.Equals("epBoard"));
                if (startIndex != -1 && endIndex != -1)
                {
                    List<ManualBoardItem> tempBoardList = mBoardList.GetRange(startIndex, endIndex - startIndex);
                    if (tempBoardList.Count > 0)
                    {
                        double sumThick = 0;
                        tempBoardList.ForEach(item => sumThick += item.PlateThick);
                        sumThick -= mBoardList[endIndex].PlateThick;
                        lists[rpIndex].L = sumThick;
                    }
                }
            }
        }

        //方铁螺丝长度计算逻辑
        private void SpaceBlockScrewLLogic()
        {
            //方铁螺丝
            double sumBoardThick = 0;
            List<ManualItem> lists = ShareItemData.MItemList;
            List<ManualBoardItem> mBoardList = AssemblyShareData.MSectionList;
            int SpaceBlockIndex = lists.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
            if (SpaceBlockIndex != -1)
            {
                int fIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("fangtie"));
                if (fIndex != -1)
                {
                    List<ManualBoardItem> tempList = mBoardList.GetRange(fIndex,
                        mBoardList.Count - fIndex);
                    tempList = tempList.FindAll(item => !item.BoardCode.Equals("epBoard") && !item.BoardCode.Equals("fpBoard"));
                    if (tempList.Count > 0)
                        tempList.ForEach(item => sumBoardThick += item.PlateThick);
                }
                //方铁锁托板 不算托板厚度 不锁 算托板厚度
                if (!MfangtieLockspBoardBox.Checked)
                {
                    int spBIndex = mBoardList.FindIndex(item => item.BoardCode.Equals("spBoard"));
                    if (spBIndex != -1)
                        sumBoardThick += mBoardList[spBIndex].PlateThick;
                }
                int moreL = MItemMoreL(lists[SpaceBlockIndex].Dim);
                lists[SpaceBlockIndex].L = (int)sumBoardThick + moreL;
            }
        }

        //更改回针UI
        private void RenderRPLUI()
        {
            List<ManualItem> ItemList = ShareItemData.MItemList;
            int rpIndex = ItemList.FindIndex(item => item.ItemCode.Equals("ReturnPin"));
            if(rpIndex != -1)
            {
                for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
                {
                    string MItemUID = ManualItemGridView.Rows[i].Cells["MItemUID"].Value.ToString();
                    if (MItemUID.Contains("ReturnPin"))
                        ManualItemGridView.Rows[i].Cells["MItemL"].Value = ItemList[rpIndex].L;
                }
            }
        }

        //更改方铁螺丝UI
        private void RenderFScrewUI()
        {
            List<ManualItem> ItemList = ShareItemData.MItemList;
            int fIndex = ItemList.FindIndex(item => item.ItemCode.Equals("SpaceBlockScrew"));
            if (fIndex != -1)
            {
                for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
                {
                    string MItemUID = ManualItemGridView.Rows[i].Cells["MItemUID"].Value.ToString();
                    if (MItemUID.Contains("SpaceBlockScrew"))
                        ManualItemGridView.Rows[i].Cells["MItemL"].Value = ItemList[fIndex].L;
                }
            }
        }

        //主界面 全量更改孔距UI
        private void RenderMainWinHoleUI()
        {
            List<ManualItem> ItemList = ShareItemData.MItemList;
            for (int i = 0; i < ManualItemGridView.Rows.Count; i++)
            {
                string MItemUID = ManualItemGridView.Rows[i].Cells["MItemUID"].Value.ToString();
                int targetIndex = ItemList.FindIndex(item => item.ItemUID.Equals(MItemUID));
                if(targetIndex != -1)
                {
                    ManualItemGridView.Rows[i].Cells["MItemDim"].Value = ItemList[targetIndex].Dim;
                        if (ItemList[targetIndex].ItemHW != 0)
                            ManualItemGridView.Rows[i].Cells["HoleW"].Value = ItemList[targetIndex].ItemHW;
                        if (ItemList[targetIndex].ItemHL != 0)
                            ManualItemGridView.Rows[i].Cells["HoleL"].Value = ItemList[targetIndex].ItemHL;
                }
            }
            List<ManualBoardItem> BoardList = AssemblyShareData.MSectionList;
            for(int i = 0; i < ManualBoardGridView.Rows.Count; i++)
            {
                string MBUID = ManualBoardGridView.Rows[i].Cells["MBUID"].Value.ToString();
                int targetIndex = BoardList.FindIndex(item => item.BoardUID.Equals(MBUID));
                if (targetIndex != -1)
                {
                    StandardType pitch = BoardList[targetIndex].PitchHoleStandard;
                    StandardType egppitch = BoardList[targetIndex].EGPPitchHoleStandard;
                    if(pitch == StandardType.Standard)
                        ManualBoardGridView.Rows[i].Cells["MHoleStandardNoEGP"].Value = "标准";
                    if (pitch == StandardType.NonStandard)
                        ManualBoardGridView.Rows[i].Cells["MHoleStandardNoEGP"].Value = "非标";
                    if (egppitch == StandardType.Standard)
                        ManualBoardGridView.Rows[i].Cells["MEGPHoleStandard"].Value = "标准";
                    if (egppitch == StandardType.NonStandard)
                        ManualBoardGridView.Rows[i].Cells["MEGPHoleStandard"].Value = "非标";
                }
            }
        }

        //手动模式 更改板列表 框UI
        private void MTypeRenderMBoardFrameUIEvent(int rowIndex)
        {
            var MBUIDValue = ManualBoardGridView.Rows[rowIndex].Cells["MBUID"].Value;
            if(MBUIDValue != null)
            {
                string MBUID = MBUIDValue.ToString();
                int targetIndex = AssemblyShareData.MSectionList.FindIndex(item => item.BoardUID.Equals(MBUID));
                if(targetIndex != -1)
                    ManualBoardGridView.Rows[rowIndex].Cells["MFrameProcess"].Value
                        = AssemblyShareData.MSectionList[targetIndex].frameItem.Tig;
            }
        }

        //手动模式 回针过推 选项
        private void MRPOverstBoardBox_CheckedChanged(object sender, EventArgs e)
        {
            ComputedRPLLogic();
            RenderRPLUI();
        }

        //手动模式 方铁螺丝锁托板 选项
        private void MfangtieLockspBoardBox_CheckedChanged(object sender, EventArgs e)
        {
            SpaceBlockScrewLLogic();
            RenderFScrewUI();
        }

        private void MComputedItemHoleBtn_Click(object sender, EventArgs e)
        {
            LJMPHole();
        }

        //手动模式 +-板 重新 设置 板顺序 后续加工需要自动计算零件穿哪些板
        public void ResetSetMBSortNum()
        {
            List<ManualBoardItem> operList = AssemblyShareData.MSectionList;
            if (operList.Count > 0)
                for (int i = 0; i < operList.Count; i++)
                    operList[i].MBSortNum = i;
        }

        //Temp Save -> Temp Record
        private void TempSaveRecordBtn_Click(object sender, EventArgs e)
        {
            Boolean tempSaveF = true;
            if (AssemblyShareData.operType == CustomOperPatternType.AUTO)
                AutoModeUpload(tempSaveF);
            if (AssemblyShareData.operType == CustomOperPatternType.MANUAL)
                ManualModeUpload(tempSaveF);
            R2DControl.SelectedIndex = 2;
        }

        private void TempRecordDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Boolean recordF = true;
            string ViewOperName = TempRecordDataGridView.Columns[e.ColumnIndex].Name;
            //点击查看
            if (ViewOperName.Equals("RecordShowOper"))
            {
                var operTypeValue = TempRecordDataGridView.Rows[e.RowIndex].Cells["OperType"].Value;
                if (operTypeValue != null)
                {
                    var RecordUIDValue = TempRecordDataGridView.Rows[e.RowIndex].Cells["TempRecordUID"].Value;
                    if(RecordUIDValue != null)
                    {
                        string utypeStr = operTypeValue.ToString();
                        String UID = RecordUIDValue.ToString();
                        
                        if (utypeStr.Equals("自动"))
                        {
                            int index = ParamsConfigData.userTempRecordList.FindIndex(item => item.UID.Equals(UID));
                            if (index != -1)
                            {
                                AMTypeUPloadRecordInfo info = ParamsConfigData.userTempRecordList[index];
                                ATypeRecordAction(info, recordF);
                                CADAuxiliaryUtils.OpenDwgByFilePath(info);
                            }
                            R2DControl.SelectedIndex = 0;
                            AssemblyShareData.operType = CustomOperPatternType.AUTO;
                        }
                        //TO EDIT 
                        if (utypeStr.Equals("手动"))
                        {
                            int index = ParamsConfigData.userTempRecordList.FindIndex(item => item.UID.Equals(UID));
                            if (index != -1)
                            {
                                AMTypeUPloadRecordInfo info = ParamsConfigData.userTempRecordList[index];
                                MTypeRecordAction(info, recordF);
                                CADAuxiliaryUtils.OpenDwgByFilePath(info);
                            }
                            R2DControl.SelectedIndex = 1;
                            AssemblyShareData.operType = CustomOperPatternType.MANUAL;
                        }
                        DelDBTempRecordInfo(UID);
                    }
                    
                }
            }
        }

        private void BoardDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (BoardDataGridView.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn &&
                e.RowIndex >= 0)
            {
                string ViewOperName = BoardDataGridView.Columns[e.ColumnIndex].Name;
                if (ViewOperName.Equals("FrameType"))
                {
                    var tempFTValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    if(tempFTValue != null)
                    {
                        string FTSelectedValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                        string FrameTypeValue = "J";
                        if (FTSelectedValue.Equals("粗框"))
                            FrameTypeValue = "C";
                        var BoardUIDValue = BoardDataGridView.Rows[e.RowIndex].Cells["BoardUID"].Value;
                        if(BoardUIDValue != null)
                        {
                            string tempBoardUID = BoardUIDValue.ToString();
                            if (tempBoardUID.Contains("fangtie"))
                            {
                                List<BoardSectionItem> targetAList = AssemblyShareData.ASectionList;
                                if (targetAList.Count > 0)
                                {
                                    for (int i = 0; i < targetAList.Count; i++)
                                    {
                                        Boolean FF = targetAList[i].BoardCode.Equals("fangtie");
                                        if (FF)
                                            targetAList[i].frameItem.FrameType = FrameTypeValue;
                                    }
                                }
                                List<BoardSectionItem> targetUIList = AssemblyShareData.AUIBlueSectionList;
                                if (targetUIList.Count > 0)
                                {
                                    for (int i = 0; i < targetUIList.Count; i++)
                                    {
                                        Boolean FF = targetUIList[i].BoardCode.Equals("fangtie");
                                        if (FF)
                                            targetUIList[i].frameItem.FrameType = FrameTypeValue;
                                    }
                                }
                            }
                            else
                            {
                                int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                if (ABIndex != -1)
                                    AssemblyShareData.ASectionList[ABIndex].frameItem.FrameType = FrameTypeValue;
                                int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                if (AUIBIndex != -1)
                                    AssemblyShareData.AUIBlueSectionList[AUIBIndex].frameItem.FrameType = FrameTypeValue;
                            }

                            int targetBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                            if (targetBIndex != -1)
                            {
                                RecognizeUtils.ATypeSetFrameItemTigInfo(targetBIndex);
                                BoardDataGridView.Rows[e.RowIndex].Cells["FrameTig"].Value = AssemblyShareData.AUIBlueSectionList[targetBIndex].frameItem.Tig;
                            }
                        }
                    }

                }

                //吊令标准
                if (ViewOperName.Equals("HangingHole"))
                {
                    var HangingHoleValue = BoardDataGridView.Rows[e.RowIndex].Cells["HangingHole"].Value;
                    var BoardUIDValue = BoardDataGridView.Rows[e.RowIndex].Cells["BoardUID"].Value;
                    if(BoardUIDValue != null)
                    {
                        string tempBoardUID = BoardUIDValue.ToString();
                        string hangValue = HangingHoleValue.ToString();
                        StandardType targetValue = StandardType.Untried;
                        if (hangValue.Equals(""))
                            targetValue = StandardType.Untried;
                        if (hangValue.Equals("标准"))
                            targetValue = StandardType.Standard;
                        if (hangValue.Equals("非标"))
                            targetValue = StandardType.NonStandard;
                        if (tempBoardUID.Contains("fangtie"))
                        {
                            List<BoardSectionItem> targetAList = AssemblyShareData.ASectionList;
                            if (targetAList.Count > 0)
                            {
                                for (int i = 0; i < targetAList.Count; i++)
                                {
                                    Boolean FF = targetAList[i].BoardCode.Equals("fangtie");
                                    if (FF)
                                        targetAList[i].Hanging.standardType = targetValue;
                                }
                            }
                            List<BoardSectionItem> targetUIList = AssemblyShareData.AUIBlueSectionList;
                            if (targetUIList.Count > 0)
                            {
                                for (int i = 0; i < targetUIList.Count; i++)
                                {
                                    Boolean FF = targetUIList[i].BoardCode.Equals("fangtie");
                                    if (FF)
                                        targetUIList[i].Hanging.standardType = targetValue;
                                }
                            }
                        }
                        else
                        {
                            int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                            if (ABIndex != -1)
                                AssemblyShareData.ASectionList[ABIndex].Hanging.standardType = targetValue;
                            int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                            if (AUIBIndex != -1)
                                AssemblyShareData.AUIBlueSectionList[AUIBIndex].Hanging.standardType = targetValue;
                        }
                    }
                }

                //孔距
                if (ViewOperName.Equals("HolePitch"))
                {
                    var HolePitchValue = BoardDataGridView.Rows[e.RowIndex].Cells["HolePitch"].Value;
                    var BoardUIDValue = BoardDataGridView.Rows[e.RowIndex].Cells["BoardUID"].Value;
                    if (BoardUIDValue != null)
                    {
                        string tempBoardUID = BoardUIDValue.ToString();
                        string hangValue = HolePitchValue.ToString();
                        StandardType targetValue = StandardType.Untried;
                        if (hangValue.Equals(""))
                            targetValue = StandardType.Untried;
                        if (hangValue.Equals("标准"))
                            targetValue = StandardType.Standard;
                        if (hangValue.Equals("非标"))
                            targetValue = StandardType.NonStandard;
                        if (tempBoardUID.Contains("fangtie"))
                        {
                            List<BoardSectionItem> targetAList = AssemblyShareData.ASectionList;
                            if(targetAList.Count > 0)
                            {
                                for(int i = 0; i < targetAList.Count; i++)
                                {
                                    Boolean FF = targetAList[i].BoardCode.Equals("fangtie");
                                    if (FF)
                                        targetAList[i].PitchHoleStandard = targetValue;
                                }
                            }
                            List<BoardSectionItem> targetUIList = AssemblyShareData.AUIBlueSectionList;
                            if(targetUIList.Count > 0)
                            {
                                for (int i = 0; i < targetUIList.Count; i++)
                                {
                                    Boolean FF = targetUIList[i].BoardCode.Equals("fangtie");
                                    if (FF)
                                        targetUIList[i].PitchHoleStandard = targetValue;
                                }
                            }
                        }
                        else
                        {
                            int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                            if (ABIndex != -1)
                                AssemblyShareData.ASectionList[ABIndex].PitchHoleStandard = targetValue;
                            int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                            if (AUIBIndex != -1)
                                AssemblyShareData.AUIBlueSectionList[AUIBIndex].PitchHoleStandard = targetValue;
                        }
                    }
                }
            }
        }

        private void BoardDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (BoardDataGridView.IsCurrentCellDirty)
                BoardDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }

        private void BoardDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
             if (BoardDataGridView.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn &&
                 e.RowIndex >= 0)
             {
                string ViewOperName = BoardDataGridView.Columns[e.ColumnIndex].Name;
                var BoardUIDValue = BoardDataGridView.Rows[e.RowIndex].Cells["BoardUID"].Value;
                if(BoardUIDValue != null)
                {
                    string tempBoardUID = BoardUIDValue.ToString();

                    if (ViewOperName.Equals("PlateThick"))
                    {
                        var PlateThickValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if(PlateThickValue != null)
                        {
                            if (double.TryParse(PlateThickValue.ToString(), out double result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    List<string> FUIDList = tempBoardUID.Split('-').ToList();
                                    if (FUIDList.Count > 0)
                                    {
                                        if (FUIDList.Count == 1)
                                        {
                                            string firstUID = FUIDList.First();
                                            int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                            item.BoardUID.Equals(firstUID));
                                            if (targetAFIndex != -1)
                                                AssemblyShareData.ASectionList[targetAFIndex].PlateThick = result;
                                        }
                                        else
                                        {
                                            for (int i = 0; i < FUIDList.Count; i++)
                                            {
                                                string targetUID = FUIDList[i];
                                                int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                                item.BoardUID.Equals(targetUID));
                                                if (targetAFIndex != -1)
                                                    AssemblyShareData.ASectionList[targetAFIndex].PlateThick = result;
                                            }
                                        }
                                    }

                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if(UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].PlateThick = result;
                                }
                                else
                                {
                                    int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (ABIndex != -1)
                                        AssemblyShareData.ASectionList[ABIndex].PlateThick = result;
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].PlateThick = result;
                                }
                            }
                        }
                    }

                    if (ViewOperName.Equals("PlateLength"))
                    {
                        var PlateLengthValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if (PlateLengthValue != null)
                        {
                            if (double.TryParse(PlateLengthValue.ToString(), out double result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    List<string> FUIDList = tempBoardUID.Split('-').ToList();
                                    if (FUIDList.Count > 0)
                                    {
                                        if (FUIDList.Count == 1)
                                        {
                                            string firstUID = FUIDList.First();
                                            int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                            item.BoardUID.Equals(firstUID));
                                            if (targetAFIndex != -1)
                                                AssemblyShareData.ASectionList[targetAFIndex].PlateLength = result;
                                        }
                                        else
                                        {
                                            for (int i = 0; i < FUIDList.Count; i++)
                                            {
                                                string targetUID = FUIDList[i];
                                                int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                                item.BoardUID.Equals(targetUID));
                                                if (targetAFIndex != -1)
                                                    AssemblyShareData.ASectionList[targetAFIndex].PlateLength = result;
                                            }
                                        }
                                    }

                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if (UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].PlateLength = result;
                                }
                                else
                                {
                                    int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (ABIndex != -1)
                                        AssemblyShareData.ASectionList[ABIndex].PlateLength = result;
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].PlateLength = result;
                                }
                            }
                        }
                    }

                    if (ViewOperName.Equals("PlateWidth"))
                    {
                        var PlateWidthValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if (PlateWidthValue != null)
                        {
                            if (double.TryParse(PlateWidthValue.ToString(), out double result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    List<string> FUIDList = tempBoardUID.Split('-').ToList();
                                    if (FUIDList.Count > 0)
                                    {
                                        if (FUIDList.Count == 1)
                                        {
                                            string firstUID = FUIDList.First();
                                            int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                            item.BoardUID.Equals(firstUID));
                                            if (targetAFIndex != -1)
                                                AssemblyShareData.ASectionList[targetAFIndex].PlateWidth = result;
                                        }
                                        else
                                        {
                                            for (int i = 0; i < FUIDList.Count; i++)
                                            {
                                                string targetUID = FUIDList[i];
                                                int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                                item.BoardUID.Equals(targetUID));
                                                if (targetAFIndex != -1)
                                                    AssemblyShareData.ASectionList[targetAFIndex].PlateWidth = result;
                                            }
                                        }
                                    }
                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if (UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].PlateWidth = result;
                                }
                                else
                                {
                                    int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (ABIndex != -1)
                                        AssemblyShareData.ASectionList[ABIndex].PlateWidth = result;
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].PlateWidth = result;
                                }
                            }
                        }
                    }

                    if (ViewOperName.Equals("PlateNum"))
                    {
                        var PlateNumValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if (PlateNumValue != null)
                        {
                            if (int.TryParse(PlateNumValue.ToString(), out int result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if (UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].Num = result;
                                }
                                else
                                {
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].Num = result;
                                }
                            }
                        }
                    }

                    if (ViewOperName.Equals("HangingDim"))
                    {
                        var HangingDimValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if (HangingDimValue != null)
                        {
                            if (double.TryParse(HangingDimValue.ToString(), out double result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    List<string> FUIDList = tempBoardUID.Split('-').ToList();
                                    if (FUIDList.Count > 0)
                                    {
                                        if (FUIDList.Count == 1)
                                        {
                                            string firstUID = FUIDList.First();
                                            int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                            item.BoardUID.Equals(firstUID));
                                            if (targetAFIndex != -1)
                                                AssemblyShareData.ASectionList[targetAFIndex].Hanging.HangingParam.Dim = result;
                                        }
                                        else
                                        {
                                            for (int i = 0; i < FUIDList.Count; i++)
                                            {
                                                string targetUID = FUIDList[i];
                                                int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                                item.BoardUID.Equals(targetUID));
                                                if (targetAFIndex != -1)
                                                    AssemblyShareData.ASectionList[targetAFIndex].Hanging.HangingParam.Dim = result;
                                            }
                                        }
                                    }
                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if (UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].Hanging.HangingParam.Dim = result;
                                }
                                else
                                {
                                    int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (ABIndex != -1)
                                        AssemblyShareData.ASectionList[ABIndex].Hanging.HangingParam.Dim = result;
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].Hanging.HangingParam.Dim = result;
                                }
                            }
                        }
                    }

                    if (ViewOperName.Equals("HangingNum"))
                    {
                        var HangingNumValue = BoardDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        if (HangingNumValue != null)
                        {
                            if (int.TryParse(HangingNumValue.ToString(), out int result))
                            {
                                if (tempBoardUID.Contains("fangtie"))
                                {
                                    List<string> FUIDList = tempBoardUID.Split('-').ToList();
                                    if (FUIDList.Count > 0)
                                    {
                                        if (FUIDList.Count == 1)
                                        {
                                            string firstUID = FUIDList.First();
                                            int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                            item.BoardUID.Equals(firstUID));
                                            if (targetAFIndex != -1)
                                                AssemblyShareData.ASectionList[targetAFIndex].Hanging.Num = result;
                                        }
                                        else
                                        {
                                            for (int i = 0; i < FUIDList.Count; i++)
                                            {
                                                string targetUID = FUIDList[i];
                                                int targetAFIndex = AssemblyShareData.ASectionList.FindIndex(item =>
                                                item.BoardUID.Equals(targetUID));
                                                if (targetAFIndex != -1)
                                                    AssemblyShareData.ASectionList[targetAFIndex].Hanging.Num = result;
                                            }
                                        }
                                    }
                                    int UIFIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(tempBoardUID));
                                    if (UIFIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[UIFIndex].Hanging.Num = result;
                                }
                                else
                                {
                                    int ABIndex = AssemblyShareData.ASectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (ABIndex != -1)
                                        AssemblyShareData.ASectionList[ABIndex].Hanging.Num = result;
                                    int AUIBIndex = AssemblyShareData.AUIBlueSectionList.FindIndex(item => item.BoardUID.Equals(BoardUIDValue));
                                    if (AUIBIndex != -1)
                                        AssemblyShareData.AUIBlueSectionList[AUIBIndex].Hanging.Num = result;
                                }
                            }
                        }
                    }
                }
            }
        }

        private void SurplusItemDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Boolean F = e.ColumnIndex == 4 || e.ColumnIndex == 5 || e.ColumnIndex == 8 || e.ColumnIndex == 9;
            if (e.RowIndex >= 0 && F)
                SurplusItemDataGridView.BeginEdit(true);
        }

        private void ItemDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Boolean F = e.ColumnIndex == 3 || e.ColumnIndex == 4 || e.ColumnIndex == 8 || e.ColumnIndex == 9;
            if (e.RowIndex >= 0 && F)
                ItemDataGridView.BeginEdit(true);
        }
    }
}
